[Django] #26461: django.db.utils.ProgrammingError: relation "..." does not exist

107 views
Skip to first unread message

Django

unread,
Apr 4, 2016, 2:51:16 PM4/4/16
to django-...@googlegroups.com
#26461: django.db.utils.ProgrammingError: relation "..." does not exist
----------------------------+------------------------------------
Reporter: prokaktus | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords: postgresql, migrations
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Hi!

{{{
psql (PostgreSQL) 9.4.5
Django==1.9.5
psycopg2==2.6.1
python2.7/python3.4
}}}

Exception occurs while running one-file migration with `AddField` and
`RenameModel`. If I split the file into different files, all migrations
passing ok. With `sqlite3`-engine issue is not reproduced, because of
that I think that it can be `postgres`-specific problem.

Minimal example of my migration file:
{{{
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Mymodel',
fields=[
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.AddField(
model_name='mymodel',
name='name',
field=models.SlugField(max_length=100, null=True),
),
migrations.RenameModel( # <- error here
old_name='Mymodel',
new_name='NewModel',
),
]
}}}

As I said above, If I split files into two or remove `AddField` or
`RenameModel` -- exception is gone. Problem not reproduced with
`CharField`, but reproduced with `ForeignKey`.

models.py:
{{{
from django.db import models


class NewModel(models.Model):
name = models.SlugField(max_length=100, null=True)
}}}

And lastly exception stacktrace:
{{{
./manage.py migrate base 0001
Operations to perform:
Target specific migration: 0001_initial, from base
Running migrations:
Rendering model states... DONE
Applying base.0001_initial...Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 353, in
execute_from_command_line
utility.execute()
File "/home/max/.virtualenvs/test_django/local/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/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/max/.virtualenvs/test_django/local/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/max/.virtualenvs/test_django/local/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/max/.virtualenvs/test_django/local/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/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/db/backends/base/schema.py", line 90, in __exit__
self.execute(sql)
File "/home/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/db/backends/base/schema.py", line 110, in execute
cursor.execute(sql, params)
File "/home/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/max/.virtualenvs/test_django/local/lib/python2.7/site-
packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "base_mymodel" does not exist
}}}

If you need any additional info, I'll be glad to provide this!

--
Ticket URL: <https://code.djangoproject.com/ticket/26461>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 4, 2016, 3:43:21 PM4/4/16
to django-...@googlegroups.com
#26461: django.db.utils.ProgrammingError: relation "..." does not exist
-------------------------------------+-------------------------------------
Reporter: prokaktus | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: duplicate
Keywords: postgresql, | Triage Stage:
migrations | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

This is a duplicate of #25530, the crash happens at index creation of the
slug field as the `CREATE INDEX` statement still refers to the original
table name.

--
Ticket URL: <https://code.djangoproject.com/ticket/26461#comment:1>

Reply all
Reply to author
Forward
0 new messages