I am using SQLAlchemy Migrate to track changes in the database and I am having trouble deleting the foreign key. I have two tables, t_new is a new table, and t_exists is an existing table. I need to add t_new and then add the foreign key to t_exists. Then I will need to cancel the operation (in which I am having problems).
t_new = sa.Table("new", meta.metadata, sa.Column("new_id", sa.types.Integer, primary_key=True) ) t_exists = sa.Table("exists", meta.metadata, sa.Column("exists_id", sa.types.Integer, primary_key=True), sa.Column( "new_id", sa.types.Integer, sa.ForeignKey("new.new_id", onupdate="CASCADE", ondelete="CASCADE"), nullable=False ) )
This works great:
t_new.create() t_exists.c.new_id.create()
But this is not so:
t_exists.c.new_id.drop() t_new.drop()
Attempting to reset the foreign key column gives an error: 1025, "Error renaming". \ my_db_name \ # sql-1b0_2e6 'to'. \ my_db_name \ exists' (errno: 150) "
If I do this using raw SQL, I can delete the foreign key manually and then delete the column, but I was not able to figure out how to remove the foreign key using SQLAlchemy? How to delete a foreign key and then a column?
python mysql foreign-keys sqlalchemy mysql-error-1025
Travis
source share