Search code examples
pythondjangodjango-modelsdatabase-migration

Fixing a typo in models.py and migration for django python project


I'm working on my first django project following along with a youtube tutorial.

In models.py while following along I made a typo...

crated_at = models.DateTimeField(default=datetime.now)

"crated_at" should be "created_at". The typo is reflected in my migrations. I tried changing both models.py and the migrations py file but it leads to an error so I changed it back to "crated". I think the problem is that the database saves the information as "crated_at". I don't want to delete the migration and redo the migrations because from what I read the database is already labeled and it won't fix the problem.

Also, I don't mind if it's left as "crated_at" in models.py and the migrations, but at least I would like it to see "created at" when I'm signed in as admin.

I want to move on but when I sign in as admin "crated at" is staring me in the face. I feel like this is a good learning moment.

Thank you.


Solution

  • I suggest keeping (restoring) the original migration with the typo, then:

    1. Fix the typo in your model
    2. Generate a new migration that contains the fix for the typo