diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2012-09-04 12:53:31 -0400 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2012-09-04 12:53:31 -0400 |
| commit | cd583d6dbd222ae61331a6965b0e1fc86c974c50 (patch) | |
| tree | d4879f277c22ca0a929e1683a98ece7d608da875 /tests | |
| parent | d865503389c7ebc1341f5b8f993858505289c6cd (diff) | |
Implement primary key changing
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/schema/tests.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/modeltests/schema/tests.py b/tests/modeltests/schema/tests.py index 6ef24ca11e..db374dc7ad 100644 --- a/tests/modeltests/schema/tests.py +++ b/tests/modeltests/schema/tests.py @@ -478,3 +478,37 @@ class SchemaTests(TestCase): "slug", connection.introspection.get_indexes(connection.cursor(), Book._meta.db_table), ) + + def test_primary_key(self): + """ + Tests altering of the primary key + """ + # Create the table + editor = connection.schema_editor() + editor.start() + editor.create_model(Tag) + editor.commit() + # Ensure the table is there and has the right PK + self.assertTrue( + connection.introspection.get_indexes(connection.cursor(), Tag._meta.db_table)['id']['primary_key'], + ) + # Alter to change the PK + new_field = SlugField(primary_key=True) + new_field.set_attributes_from_name("slug") + editor = connection.schema_editor() + editor.start() + editor.delete_field(Tag, Tag._meta.get_field_by_name("id")[0]) + editor.alter_field( + Tag, + Tag._meta.get_field_by_name("slug")[0], + new_field, + ) + editor.commit() + # Ensure the PK changed + self.assertNotIn( + 'id', + connection.introspection.get_indexes(connection.cursor(), Tag._meta.db_table), + ) + self.assertTrue( + connection.introspection.get_indexes(connection.cursor(), Tag._meta.db_table)['slug']['primary_key'], + ) |
