K
K
Klaus Kater2015-08-19 11:49:22
PostgreSQL
Klaus Kater, 2015-08-19 11:49:22

How to fix migration error "ProgrammingError: column "file_id" cannot be cast automatically to type integer" django and postgres?

Hello, I've run into a strange problem.
models:

class Document(Model):
    owner = models.ForeignKey('auth.User', verbose_name=u'Владелец')
    title = models.CharField(verbose_name=u'Название', max_length=100)
    description = models.CharField(verbose_name=u'Описание', max_length=1000, null=True, blank=True)
    file_obj = models.ForeignKey('common.File', verbose_name=u'Файлы', blank=True, null=True)

def get_file_path(instance, filename):
    ext = filename.split('.')[-1]
    filename = "%s.%s" % (uuid.uuid4(), ext)
    return os.path.join('files', filename)

class File(Model):
    owner = models.ForeignKey('auth.User', verbose_name=u'Владелец')
    name = models.CharField(verbose_name=u'Название', max_length=1000, null=True, blank=True)
    file_storage = models.FileField(verbose_name=u'Сам файл', upload_to=get_file_path)

An error occurs during migration:
ProgrammingError: column "file_id" cannot be cast automatically to type integer
HINT:  Specify a USING expression to perform the conversion.

Google didn't say anything useful about it. Why he does not like file_id - I do not understand.
The Internet advises to recreate the field again manually, so I don’t even understand from which model this field is taken.
Tried deleting the database completely, didn't help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Klaus Kater, 2015-08-19
@kurojneko

The problems were in the migrations from the old base, I cleaned them up, the migrations started working.
Plus, for some reason postgres did not want to see the standard user, it said
relation "auth_user" does not exist
is solved by separate migrations:
python manage.py migrate auth
python manage.py migrate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question