From 0f58db9d645383db48e402f69d733b2013a6748e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 3 Dec 2015 14:21:13 -0500 Subject: [PATCH] Run NOT NULL alterations before foreign key adds The "migrate resources table" migration will fail for some MariaDB versions if the NOT NULL alteration is applied after the foreign key constraint has been added [1]. This patch reverses the order so that NOT NULL is applied first. [1] http://paste.openstack.org/show/480820/ Change-Id: Iab2b9fc7d82c739ae458ee48c1830541fb0f9579 --- .../8a6d8bdae39_migrate_neutron_resources_table.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/neutron/db/migration/alembic_migrations/versions/mitaka/contract/8a6d8bdae39_migrate_neutron_resources_table.py b/neutron/db/migration/alembic_migrations/versions/mitaka/contract/8a6d8bdae39_migrate_neutron_resources_table.py index b2a424ce0..e7acce8ba 100644 --- a/neutron/db/migration/alembic_migrations/versions/mitaka/contract/8a6d8bdae39_migrate_neutron_resources_table.py +++ b/neutron/db/migration/alembic_migrations/versions/mitaka/contract/8a6d8bdae39_migrate_neutron_resources_table.py @@ -49,15 +49,18 @@ standardattrs = sa.Table( def upgrade(): generate_records_for_existing() for table, model in TABLE_MODELS: - # add the constraint now that everything is populated on that table + # add constraint(s) now that everything is populated on that table. + # note that some MariaDB versions will *not* allow the ALTER to + # NOT NULL on a column that has an FK constraint, so we set NOT NULL + # first, then the FK constraint. + op.alter_column(table, 'standard_attr_id', nullable=False, + existing_type=sa.BigInteger(), existing_nullable=True, + existing_server_default=False) op.create_foreign_key( constraint_name=None, source_table=table, referent_table='standardattributes', local_cols=['standard_attr_id'], remote_cols=['id'], ondelete='CASCADE') - op.alter_column(table, 'standard_attr_id', nullable=False, - existing_type=sa.BigInteger(), existing_nullable=True, - existing_server_default=False) op.create_unique_constraint( constraint_name='uniq_%s0standard_attr_id' % table, table_name=table, columns=['standard_attr_id']) -- 2.45.2