Allow Me to Reintroduce Myself

akugel | Oct. 13, 2022, 3:26 p.m.

So disaster struck in the django unchained world. Originally the “About” section of this website was just hardcoded html. This was not in the spirit of the sleek dynamic content that this website soughts to provide. As such, I decided to create a model for the contributors of this website. Originally this would be an orphan table, but that wouldn’t be in the spirit of a RDBMS. So I decided that the Author model would effectively be a subclass of the User model that comes built into django. I would then have a one to one relationship between the users and the authors.

One to one db relationships have a mandatory foreign key. Because I was creating the author table and it didn’t exist yet, postgres didn’t like this. I ended up compounding a bad decision by messing with postgres directly instead of via migrations…which borked the entire db. It was completely hosed.

To salvage this situation, I used my api endpoint to take a dump of all posts and comments, and saved them to json files. I then completely nuked everything in the public schema in the postgres database. I deleted my migration file, recreated the migrations from scratch, and migrated them. This fixed the issue. I then used the requests module in python to recreate all of my posts and comments. A side effect of this was that I couldn't manually create a creation date for my posts, which is why everything was created on october 11th. Still, this is a small price to pay for a working database.

Moral of the story, do not manually mess with postgres. Always use migrations. Always.

Leave a comment

About Me

I'm Anthony Kugel, a cloud engineer and freelance web developer. I made this site with the help of djangocentral.com.

LinkedIn
What I'm listening To