dimanche 19 juin 2016

Django PostgreSQL migration error

When I'm trying to do a migration: python manage.py migrate I have an error: How to fix it?

Python version: 2.7

Django version: 1.8

I'm using PostgreSQL

When creating database from scratch it works perfectly, but can't do that every time I change something in models.

System check identified some issues:

WARNINGS:
?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DIRS, TEMPLATE_DEBUG.
Operations to perform:
  Apply all migrations: authtoken, account, sessions, admin, ifit, sites, auth, contenttypes, socialaccount
Running migrations:
  Rendering model states... DONE
  Applying ifit.0004_auto_20160618_0912...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 482, in alter_field
    old_db_params, new_db_params, strict)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/backends/postgresql/schema.py", line 110, in _alter_field
    new_db_params, strict,
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 491, in _alter_field
    fk_names = self._constraint_names(model, [old_field.column], foreign_key=True)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 911, in _constraint_names
    constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/backends/postgresql/introspection.py", line 218, in get_constraints
    """, [table_name])
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/bluhome/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: function unnest(int2vector) does not exist
LINE 6:                     FROM unnest(idx.indkey) i
                                 ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Here is migration:

# -*- coding: utf-8 -*-
# Generated by Django 1.9.3 on 2016-06-18 09:12
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('ifit', '0003_auto_20160618_0842'),
    ]

    operations = [
        migrations.AlterField(
            model_name='challengedata',
            name='user',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
        ),
    ]

However this migrations worked fine:

# -*- coding: utf-8 -*-
# Generated by Django 1.9.3 on 2016-06-18 09:34
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('ifit', '0003_auto_20160618_0842'),
    ]

    operations = [
        migrations.AlterField(
            model_name='challengedata',
            name='state',
            field=models.CharField(choices=[(b'RC', b'otrzymany'), (b'AC', b'zaakceptowany'), (b'DC', b'odrzucony'), (b'CC', b'anulowany'), (b'DN', b'wykonany'), (b'FD', b'niewykonany')], max_length=2),
        ),
    ]

It seems like problem is when I add null=True to ForeignKey field. However just removing field from model: owner = models.ForeignKey(User) also raises same error.

Don't know what it's all about. Thank You in advance for help.

Aucun commentaire:

Enregistrer un commentaire