Opened 9 years ago

Closed 9 years ago

#26461 closed Bug (duplicate)

django.db.utils.ProgrammingError: relation "..." does not exist

Reported by: Maxim Filipenko Owned by: nobody
Component: Migrations Version: 1.9
Severity: Normal Keywords: postgresql, migrations
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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!

Change History (1)

comment:1 by Simon Charette, 9 years ago

Resolution: duplicate
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top