M
M
Maxim Stikharev2018-05-13 11:34:15
Python
Maxim Stikharev, 2018-05-13 11:34:15

Why it is impossible to address from this part of request?

I use psycopg2
joxi.ru/LmGeRznSweYqbA -
database query table -

curr.execute("INSERT INTO public.instagram_post VALUES (post_id,link,image,like_count,comment,comment_count,login_id)",
                     [id,link,photo,comment,comment_count,account[1]])

Mistake:
psycopg2.ProgrammingError: ОШИБКА:  столбец "post_id" не существует
LINE 1: INSERT INTO public.instagram_post VALUES (post_id,link,image...
                                                  ^
HINT:  Столбец "post_id" есть в таблице "instagram_post", но на него нельзя ссылаться из этой части запроса.

Model in Django
class Post(models.Model):
    login = models.ForeignKey(Instagram, on_delete=models.CASCADE)
    post_id = models.PositiveIntegerField(primary_key=True)
    link = models.CharField(max_length=300)
    image = models.CharField(max_length=300)
    like_count = models.PositiveIntegerField(default=0)
    comment = models.CharField(max_length=1500, blank=True)
    comment_count = models.PositiveIntegerField(default=0)

What could be wrong? Error and HINT contradict each other (or am I doing something wrong?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Neyury, 2018-05-13
@maximifn

You can use the ORM and django models anywhere in this way:

import os
import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") # путь к файлу настроек
django.setup()

If you can't import project.settings, then you can additionally write at the beginning
import sys

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) # В последнем параметре указываем путь, откуда можно сделать импорт.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question