#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.82eeba2e8d79163bc5a14243d991e291%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to