Reputation: 954
class Migration(migrations.Migration):
dependencies = [
("buckets", "0001_auto_20230420_2018"),
]
operations = [
# Delete existing tables
migrations.RunSQL(
sql=buckets.my_models.models.RefObjModel.get_create_table_sql(),
reverse_sql=migrations.RunSQL.noop,
),
Above is a code sample, we have a migration file.
Question: We have to remove RefObjModel, how we should be doing it, what is preferred approach. If we are deleting the class file/code application run is failing as it tries to run all the migration file and unable to find referenced class.
If we delete the references from all the migration files manually, does it create any problem in production deployment/application
Upvotes: 0
Views: 41
Reputation: 63
No there should be no problem, the only solution is to remove manually all occurrences of the RefObjModel from all migration files, just delete the block:
migrations.RunSQL(
sql=buckets.my_models.models.RefObjModel.get_create_table_sql(),
reverse_sql=migrations.RunSQL.noop,
),
even if you ended up with an empty list in the operations variable Do not delete the migration file.
To test it just run the migrations on an empty database and everything should be ok.
Upvotes: 0
Reputation: 33
In order to remove RefObjModel, you have to delete it from it's corresponding model.
Usually it is not preferable to modify the migration files manually (unless a person really really knows what he is doing)
After modifying the model if you then rerun the migrations again I believe the RefObjModel won't appear.
Upvotes: 0