Make those Migrations

Jun 04 2018

Picture here

I am close to finishing another project that resembles a reddit clone. Basically, it involves creating a user and then that user being able to post urls to the homepage. In order to achieve this, a Post model had to be created. All it basically contained was a title, url, time posted and who it was posted by. Basic Model Fields were used to get this to work.


However, as I was going through the testing, I kept getting Operational Errors, for example a "no such column exists" error. These pointed to a database issue but it took me a while to figure out why it was popping up. Fortunately/unfortunately the answer was simple, I had not performed


python manage.py makemigrations AND THEN python manage.py migrate.


"Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations, when to run them, and the common problems you might run into." (djangoproject).


After I performed these the site worked. Well...almost, I was still missing the time posted element. This was a bit of a sad one since it turn out I just forgot the () at the end of DateTimeField(). Even sadder when I fixed this and still had no result, it took me a while to figure out that I need to makemigrations and migrate again! The good thing is that this isn't a major issue and will certainly become automatic the more I work with Django, still...it was amusingly frustrating trying to figure out the problem...and then the solution to be almost trivial.