Paul404
Paul404

Reputation: 27

Removing a Django migration after "makemigration" but before "migrate"

Apologies for the very basic nature of the question; I am a beginner here with Django. I don't want to mess up the migration structure of my app.

I am using Django 3.0.2. with a Postgresql DB.

My app is "myapp" and myapp has had several successful migrations thus far.

Then today I made more changes to my existing model.

In Mac terminal I then ran:

python manage.py makemigrations myapp

A migration file was created

Migrations for 'myapp':
 myapp/migrations/0007_auto_20200117_0814.py
  - Add field myfield to appTable

However, before running "migrate" on this migration (i.e., "0007_auto_20200117_0814.py"), I have seen an error in my approach to the model change I wish to make, so I want to remove the above migration -- in other words, I do not want to run "migrate" on it. I just want it to ... go away, for lack of a better phrase. I then would like to make some changes to my model and re-run "makemigrations."

I've googled around and almost all answers I found regarding "deleting" a migration appear to assume that the "migrate" command was already run on the migration.

My question, how does one safely remove a migration after "makemigrations" command was run but before "migrate". Can I just go into the myapp/migration folder and delete the unwanted migration without any undesirable side effects?

Upvotes: 1

Views: 341

Answers (1)

rob
rob

Reputation: 2144

Yes, you can safely delete your un-ran migration file without any changes to your database. Unless you actually run the created migration, it will not have generated any database changes.

Upvotes: 2

Related Questions