Ticket #403 (closed defect: fixed)
MySQL misbehaves when a forwards() data migration doesn't work out
| Reported by: | dpmcgee@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 0.7.1 |
| Component: | migrations | Version: | 0.7 |
| Keywords: | mysql | Cc: |
Description
If the forwards() migration blows up for some reason, you get a bunch of stuff telling you that your migration wasn't marked no-dry-run, rather than seeing the actual reason the migration failed.
In this case, we have a very isolated test case set up that will always fail (trying to NULL out a non-null column), but it behaves correctly on SQLite and tells you what you are doing wrong, whereas in MySQL you get the below misleading error.
I've attached a sample app that can fully reproduce this case. There is an SQLite DB included as well to see that it in fact works fine (e.g. fails correctly) with that database engine.
Here are the steps necessary to reproduce (a mix of SQL and shell commands):
create database southbug;
create user southbug identified by 'southbug';
grant all on southbug.* to southbug;
./manage.py syncdb
./manage.py miggrate bug 0001
use southbug;
insert into bug_bug values ('testing 1', 1);
insert into bug_bug values ('testing 2', 2);
insert into bug_bug values ('testing 3', 3);
Then do the following:
$ ./manage.py migrate bug
Running migrations for bug:
- Migrating forwards to 0002_values_to_null.
- Migration 'bug:0002_values_to_null' is marked for no-dry-run.
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/lib/python2.6/site-packages/django/core/management/init.py", line 362, in execute_manager
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/init.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, options.dict)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, options)
File "/usr/lib/python2.6/site-packages/south/management/commands/migrate.py", line 102, in handle
delete_ghosts = delete_ghosts,
File "/usr/lib/python2.6/site-packages/south/migration/init.py", line 202, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/usr/lib/python2.6/site-packages/south/migration/migrators.py", line 215, in migrate_many
result = migrator.class.migrate_many(migrator, target, migrations, database)
File "/usr/lib/python2.6/site-packages/south/migration/migrators.py", line 284, in migrate_many
result = self.migrate(migration, database)
File "/usr/lib/python2.6/site-packages/south/migration/migrators.py", line 121, in migrate
result = self.run(migration)
File "/usr/lib/python2.6/site-packages/south/migration/migrators.py", line 95, in run
return self.run_migration(migration)
File "/usr/lib/python2.6/site-packages/south/migration/migrators.py", line 82, in run_migration
print self.run_migration_error(migration)
File "/usr/lib/python2.6/site-packages/south/migration/migrators.py", line 278, in run_migration_error
(self.format_backwards(migration), extra_info))
File "/usr/lib/python2.6/site-packages/south/migration/migrators.py", line 265, in format_backwards
self.backwards(migration)()
File "/usr/lib/python2.6/site-packages/south/migration/migrators.py", line 56, in <lambda>
return (lambda: direction(orm))
File "/tmp/southbug/bug/migrations/0002_values_to_null.py", line 15, in backwards
orm.Bug.objects.all().update(fieldname='testing ' + models.F('id'))
File "/usr/lib/python2.6/site-packages/south/orm.py", line 396, in getattr
raise AttributeError?("You are in a dry run, and cannot access the ORM.\nWrap ORM sections in 'if not db.dry_run:', or if the whole migration is only a data migration, set no_dry_run = True on the Migration class.")
AttributeError?: You are in a dry run, and cannot access the ORM.
Wrap ORM sections in 'if not db.dry_run:', or if the whole migration is only a data migration, set no_dry_run = True on the Migration class.
Attachments
Change History
Changed 3 years ago by dpmcgee@…
- Attachment southbug.tar.gz added
comment:1 Changed 3 years ago by andrew
- Status changed from new to closed
- Resolution set to fixed
- Milestone set to 0.7.1
Now fixed in [9f0aac73bdf9].

Example app to reproduce