diff --git a/playhouse/migrate.py b/playhouse/migrate.py index c01a2d6a5..8c470169c 100644 --- a/playhouse/migrate.py +++ b/playhouse/migrate.py @@ -836,7 +836,7 @@ def _fix_index(self, sql, column_to_update, new_column): @operation def drop_column(self, table, column_name, cascade=True, legacy=False): - if sqlite3.version_info >= (3, 25, 0) and not legacy: + if sqlite3.sqlite_version_info >= (3, 25, 0) and not legacy: ctx = self.make_context() (self._alter_table(ctx, table) .literal(' DROP COLUMN ') @@ -846,7 +846,7 @@ def drop_column(self, table, column_name, cascade=True, legacy=False): @operation def rename_column(self, table, old_name, new_name, legacy=False): - if sqlite3.version_info >= (3, 25, 0) and not legacy: + if sqlite3.sqlite_version_info >= (3, 25, 0) and not legacy: return (self ._alter_table(self.make_context(), table) .literal(' RENAME COLUMN ') diff --git a/tests/migrations.py b/tests/migrations.py index 1d4c3dcdb..d6f73e2be 100644 --- a/tests/migrations.py +++ b/tests/migrations.py @@ -580,7 +580,8 @@ class Meta: self.assertEqual(foreign_key.dest_table, 'person') def test_drop_foreign_key(self): - migrate(self.migrator.drop_column('page', 'user_id')) + kw = {'legacy': True} if IS_SQLITE else {} + migrate(self.migrator.drop_column('page', 'user_id', **kw)) columns = self.database.get_columns('page') self.assertEqual( sorted(column.name for column in columns), @@ -664,19 +665,19 @@ def test_alter_column_type(self): @requires_sqlite def test_valid_column_required(self): self.assertRaises( - ValueError, + (OperationalError, ValueError), migrate, self.migrator.drop_column('page', 'column_does_not_exist')) self.assertRaises( - ValueError, + (OperationalError, ValueError), migrate, self.migrator.rename_column('page', 'xx', 'yy')) @requires_sqlite @requires_models(IndexModel) def test_table_case_insensitive(self): - migrate(self.migrator.drop_column('PaGe', 'name')) + migrate(self.migrator.drop_column('PaGe', 'name', legacy=True)) column_names = self.get_column_names('page') self.assertEqual(column_names, set(['id', 'user_id'])) @@ -685,7 +686,8 @@ def test_table_case_insensitive(self): column_names = self.get_column_names('page') self.assertEqual(column_names, set(['id', 'user_id', 'testing'])) - migrate(self.migrator.drop_column('indeX_mOdel', 'first_name')) + migrate(self.migrator.drop_column('indeX_mOdel', 'first_name', + legacy=True)) indexes = self.migrator.database.get_indexes('index_model') self.assertEqual(len(indexes), 1) self.assertEqual(indexes[0].name, 'index_model_data') @@ -759,7 +761,8 @@ def test_index_preservation(self): migrate(self.migrator.rename_column( 'index_model', 'first_name', - 'first')) + 'first', + legacy=True)) queries = [x.msg for x in self.history] self.assertEqual(queries, [ @@ -818,7 +821,7 @@ def test_modify_fk_constraint(self): self.reset_sql_history() new_fk = ForeignKeyField(User, User.id, null=True, on_delete='CASCADE') migrate( - self.migrator.drop_column('page', 'user_id'), + self.migrator.drop_column('page', 'user_id', legacy=True), self.migrator.add_column('page', 'user_id', new_fk)) queries = [x.msg for x in self.history] diff --git a/tests/regressions.py b/tests/regressions.py index 193b0098e..a47d8a20e 100644 --- a/tests/regressions.py +++ b/tests/regressions.py @@ -1365,9 +1365,10 @@ class TestFKMigrationRegression(ModelTestCase): def test_fk_migration(self): migrator = SchemaMigrator.from_database(self.database) + kw = {'legacy': True} if IS_SQLITE else {} migrate(migrator.drop_column( FKMB._meta.table_name, - FKMB.fkma.column_name)) + FKMB.fkma.column_name, **kw)) migrate(migrator.add_column( FKMB._meta.table_name,