Last active
December 31, 2015 10:39
-
-
Save loic/7975021 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tests/migrations/test_bug/0001_initial.py b/tests/migrations/test_bug/0001_initial.py | |
new file mode 100644 | |
index 0000000..b07efdf | |
--- /dev/null | |
+++ b/tests/migrations/test_bug/0001_initial.py | |
@@ -0,0 +1,13 @@ | |
+from django.db import migrations, models | |
+ | |
+ | |
+class Migration(migrations.Migration): | |
+ | |
+ operations = [ | |
+ migrations.CreateModel( | |
+ name='NewModel', | |
+ fields=[ | |
+ ('id', models.AutoField(primary_key=True)), | |
+ ], | |
+ ), | |
+ ] | |
diff --git a/tests/migrations/test_bug/0002_data.py b/tests/migrations/test_bug/0002_data.py | |
new file mode 100644 | |
index 0000000..8b83ce3 | |
--- /dev/null | |
+++ b/tests/migrations/test_bug/0002_data.py | |
@@ -0,0 +1,18 @@ | |
+# encoding: utf8 | |
+from django.db import models, migrations | |
+ | |
+ | |
+def create_data(models, schema_editor): | |
+ NewModel = models.get_model("migrations", "NewModel") | |
+ NewModel.objects.create() | |
+ NewModel.objects.create() | |
+ NewModel.objects.create() | |
+ | |
+ | |
+class Migration(migrations.Migration): | |
+ | |
+ dependencies = [('migrations', '0001_initial')] | |
+ | |
+ operations = [ | |
+ migrations.RunPython(create_data) | |
+ ] | |
diff --git a/tests/migrations/test_bug/0003_bug.py b/tests/migrations/test_bug/0003_bug.py | |
new file mode 100644 | |
index 0000000..83adff7 | |
--- /dev/null | |
+++ b/tests/migrations/test_bug/0003_bug.py | |
@@ -0,0 +1,15 @@ | |
+# encoding: utf8 | |
+from django.db import models, migrations | |
+ | |
+ | |
+class Migration(migrations.Migration): | |
+ | |
+ dependencies = [('migrations', '0002_data')] | |
+ | |
+ operations = [ | |
+ migrations.AddField( | |
+ field=models.PositiveIntegerField(default=0, verbose_name=u'New Field'), | |
+ name='new_field', | |
+ model_name='NewModel', | |
+ ), | |
+ ] | |
diff --git a/tests/migrations/test_bug/__init__.py b/tests/migrations/test_bug/__init__.py | |
new file mode 100644 | |
index 0000000..e69de29 | |
diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py | |
index 5c0131d..48f6eef 100644 | |
--- a/tests/migrations/test_executor.py | |
+++ b/tests/migrations/test_executor.py | |
@@ -14,6 +14,15 @@ class ExecutorTests(MigrationTestBase): | |
available_apps = ["migrations", "django.contrib.sessions"] | |
+ @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_bug"}) | |
+ def test_bug(self): | |
+ executor = MigrationExecutor(connection) | |
+ executor.recorder.flush() | |
+ try: | |
+ executor.migrate([("migrations", "0003_bug")]) | |
+ finally: | |
+ executor.recorder.flush() | |
+ | |
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) | |
def test_run(self): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ PYTHONPATH=. python3 tests/runtests.py migrations | |
Testing against Django installed in '/Users/loic/Dev/django/django' | |
Creating test database for alias 'default'... | |
Creating test database for alias 'other'... | |
...........................................................E..........s.......... | |
====================================================================== | |
ERROR: test_bug (migrations.test_executor.ExecutorTests) | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "/Users/loic/Dev/django/django/db/backends/utils.py", line 61, in execute | |
return self.cursor.execute(sql, params) | |
File "/Users/loic/Dev/django/django/db/backends/sqlite3/base.py", line 489, in execute | |
return Database.Cursor.execute(self, query, params) | |
sqlite3.IntegrityError: migrations_newmodel__new.new_field may not be NULL | |
The above exception was the direct cause of the following exception: | |
Traceback (most recent call last): | |
File "/Users/loic/Dev/django/django/test/utils.py", line 217, in inner | |
return test_func(*args, **kwargs) | |
File "/Users/loic/Dev/django/tests/migrations/test_executor.py", line 22, in test_bug | |
executor.migrate([("migrations", "0003_bug")]) | |
File "/Users/loic/Dev/django/django/db/migrations/executor.py", line 60, in migrate | |
self.apply_migration(migration, fake=fake) | |
File "/Users/loic/Dev/django/django/db/migrations/executor.py", line 94, in apply_migration | |
migration.apply(project_state, schema_editor) | |
File "/Users/loic/Dev/django/django/db/migrations/migration.py", line 97, in apply | |
operation.database_forwards(self.app_label, schema_editor, project_state, new_state) | |
File "/Users/loic/Dev/django/django/db/migrations/operations/fields.py", line 30, in database_forwards | |
schema_editor.add_field(from_model, to_model._meta.get_field_by_name(self.name)[0]) | |
File "/Users/loic/Dev/django/django/db/backends/sqlite3/schema.py", line 90, in add_field | |
self._remake_table(model, create_fields=[field]) | |
File "/Users/loic/Dev/django/django/db/backends/sqlite3/schema.py", line 62, in _remake_table | |
self.quote_name(model._meta.db_table), | |
File "/Users/loic/Dev/django/django/db/backends/schema.py", line 95, in execute | |
cursor.execute(sql, params) | |
File "/Users/loic/Dev/django/django/db/backends/utils.py", line 61, in execute | |
return self.cursor.execute(sql, params) | |
File "/Users/loic/Dev/django/django/db/utils.py", line 93, in __exit__ | |
six.reraise(dj_exc_type, dj_exc_value, traceback) | |
File "/Users/loic/Dev/django/django/utils/six.py", line 495, in reraise | |
raise value.with_traceback(tb) | |
File "/Users/loic/Dev/django/django/db/backends/utils.py", line 61, in execute | |
return self.cursor.execute(sql, params) | |
File "/Users/loic/Dev/django/django/db/backends/sqlite3/base.py", line 489, in execute | |
return Database.Cursor.execute(self, query, params) | |
django.db.utils.IntegrityError: migrations_newmodel__new.new_field may not be NULL | |
---------------------------------------------------------------------- | |
Ran 81 tests in 0.462s | |
FAILED (errors=1, skipped=1) | |
Destroying test database for alias 'default'... | |
Destroying test database for alias 'other'... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment