Changes between Initial Version and Version 8 of Ticket #24061


Ignore:
Timestamp:
Jan 5, 2015, 8:56:35 AM (10 years ago)
Author:
Andriy Sokolovskiy
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24061

    • Property Owner changed from nobody to Andriy Sokolovskiy
    • Property Status newassigned
    • Property Component Database layer (models, ORM)Migrations
    • Property Triage Stage UnreviewedAccepted
    • Property Summary SQLite backend: Deleting last field from model: migration generates SQL with Syntax ErrorWhen deleting a model with foreignkey, redundant RemoveField created.
    • Property Version 1.7master
  • Ticket #24061 – Description

    initial v8  
    2020}}}
    2121
    22 Here is what happens:
     22Here is what happens: https://dpaste.de/LYqP
     23
     24
     25----
     26
     27'''RELATED ISSUE:''
     28
     29Consider following:
    2330
    2431{{{
    25 $ python -m pdb manage.py test
    26 > d:\projects\galago\bug\sqlitebug\manage.py(2)<module>()
    27 -> import os
    28 (Pdb) c
    29 Creating test database for alias 'default'...
    30 Traceback (most recent call last):
    31   File "c:\Python27\Lib\pdb.py", line 1314, in main
    32     pdb._runscript(mainpyfile)
    33   File "c:\Python27\Lib\pdb.py", line 1233, in _runscript
    34     self.run(statement)
    35   File "c:\Python27\Lib\bdb.py", line 400, in run
    36     exec cmd in globals, locals
    37   File "<string>", line 1, in <module>
    38   File "manage.py", line 2, in <module>
    39     import os
    40   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
    41     utility.execute()
    42   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\__init__.py", line 377, in execute
    43     self.fetch_command(subcommand).run_from_argv(self.argv)
    44   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\commands\test.py", line 50, in run_from_argv
    45     super(Command, self).run_from_argv(argv)
    46   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
    47     self.execute(*args, **options.__dict__)
    48   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\commands\test.py", line 71, in execute
    49     super(Command, self).execute(*args, **options)
    50   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\base.py", line 338, in execute
    51     output = self.handle(*args, **options)
    52   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\commands\test.py", line 88, in handle
    53     failures = test_runner.run_tests(test_labels)
    54   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\test\runner.py", line 147, in run_tests
    55     old_config = self.setup_databases()
    56   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\test\runner.py", line 109, in setup_databases
    57     return setup_databases(self.verbosity, self.interactive, **kwargs)
    58   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\test\runner.py", line 299, in setup_databases
    59     serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
    60   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\backends\creation.py", line 377, in create_test_db
    61     test_flush=True,
    62   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\__init__.py", line 115, in call_command
    63     return klass.execute(*args, **defaults)
    64   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\base.py", line 338, in execute
    65     output = self.handle(*args, **options)
    66   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\core\management\commands\migrate.py", line 160, in handle
    67     executor.migrate(targets, plan, fake=options.get("fake", False))
    68   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\migrations\executor.py", line 63, in migrate
    69     self.apply_migration(migration, fake=fake)
    70   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\migrations\executor.py", line 97, in apply_migration
    71     migration.apply(project_state, schema_editor)
    72   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\migrations\migration.py", line 107, in apply
    73     operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
    74   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards
    75     schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0])
    76   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\backends\sqlite3\schema.py", line 185, in remove_field
    77     self._remake_table(model, delete_fields=[field])
    78   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\backends\sqlite3\schema.py", line 135, in _remake_table
    79     self.quote_name(model._meta.db_table),
    80   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\backends\schema.py", line 99, in execute
    81     cursor.execute(sql, params)
    82   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\backends\utils.py", line 65, in execute
    83     return self.cursor.execute(sql, params)
    84   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\utils.py", line 94, in __exit__
    85     six.reraise(dj_exc_type, dj_exc_value, traceback)
    86   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\backends\utils.py", line 65, in execute
    87     return self.cursor.execute(sql, params)
    88   File "c:\Users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\backends\sqlite3\base.py", line 485, in execute
    89     return Database.Cursor.execute(self, query, params)
    90 OperationalError: near ")": syntax error
    91 Uncaught exception. Entering post mortem debugging
    92 Running 'cont' or 'step' will restart the program
    93 > c:\users\sonoflilit\.virtualenvs\galago\lib\site-packages\django\db\backends\sqlite3\base.py(485)execute()
    94 -> return Database.Cursor.execute(self, query, params)
    95 (Pdb) print query
    96 INSERT INTO "bug_b__new" () SELECT  FROM "bug_b"
     32
     33class ModelA(models.Model):
     34    field1 = models.BooleanField(default=False)
     35
     36class ModelB(models.Model):
     37    another_field1 = models.TextField(blank=True)
     38    related_field = models.ForeignKey(ModelA)
    9739}}}
     40
     41After creating inital migration, I deleted model, so migration will look like:
     42
     43{{{
     44
     45class Migration(migrations.Migration):
     46
     47    dependencies = [
     48        ('blankapp', '0001_initial'),
     49    ]
     50
     51    operations = [
     52        migrations.RemoveField(
     53            model_name='modelb',
     54            name='related_field',
     55        ),
     56        migrations.DeleteModel(
     57            name='ModelB',
     58        ),
     59    ]
     60}}}
     61
     62And, when you will try to migrate backwards, LookupError: App 'blankapp' doesn't have a 'modelb' model. will be raised, because migration will try to add related_field to model which does not exists yet.
Back to Top