aubaub
aubaub

Reputation: 380

Make Django forget an incorrect 'makemigration'

I'm working on a Django app where I've migrated my basic model. There is no data saved to the table representing this model (I'm using PostgreSQL). I've since added a new variable under the original model class, something like:

time_entered = models.DateTimeField(auto_now_add=True)  

I must entered a default time in an invalid format, maybe default = datetime.datetime.now(), because Django gave me an error when I tried to migrate the new variable:

Running migrations:
Applying app.0002_model_time_entered... Traceback:
...
django.core.exceptions.ValidationError: ["'' value has an invali format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]

I've commented out time_entered, I've used Django's timezone to set the default value to the correct format, and I've set the default value to a string in the correct format. Each time, when I try makemigrations and migrate, I get that same error and Django won't commit my changes to the database. I'm even getting the error when I try to look at the SQL commands with sqlmigrate. (To clarify, sqlmigrate works for recent makemigrations with minor changes, but not the early, uncommitted makemigration attempts that had the actual error.)

What can I do? How can I get Django to stop being stubborn and let go of that old, wrong SQL command? Is there a way to delete any uncommitted SQL commands from makemigration? I can't migrate anything right now.

Upvotes: 3

Views: 1228

Answers (2)

joeskru
joeskru

Reputation: 242

https://south.readthedocs.org/en/latest/tutorial/part3.html

./manage.py schemamigration [myapp] --auto --update

rolls back the last migration

Upvotes: 1

aubaub
aubaub

Reputation: 380

Used and unused migrations hang out in ./app/migrations. I deleted all migration files after the initial migration, then ran a new makemigrations that didn't have the format error.

I'm not satisfied with this as a solution. I'd still love to hear a better answer.

Upvotes: 1

Related Questions