Kicking Bugs Out: Django + Postgresql Migrations, plus more bugs showing up...

Bismillah,

Asalaam Aleykum brothers and sisters, I hope your weekend was refreshing. Welcome back to the blog.

As you might remember, in the previous article I had the following bug:

raise MigrationSchemaMissing( django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (no schema has been selected to create in LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...

What's That Mate(Insert Australian accent)?

Now, what this bug basically means is that Django was unable to migrate changes to the Postgresql database.

After doing some research, I realised the issue came from two things:

  1. Not specifying the database and/or schema to perform migrations on.

  2. The user specified did not have the proper privileges for Django to make such changes to the specified database.

So how do we solve this?

Well, the solution is quite simple mate, although not easy to find.

Two things:

  1. Change the user specified to one with proper privileges on the DB

    While making migrations, Django expects the user selected to have the proper privileges to manipulate the specified DB.

    So this action will be in the settings.py file as follows:

    DATABASES = {

    'default': {

    'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': ‘<db_name>’,

    'USER': '<db_username>',

    'PASSWORD': '<password>',

    'HOST': '<db_hostname_or_ip>',

    'PORT': '<db_port>',

    }

    }

    <db_name>: the name of the database in Postgresql

    <db_username>: name of the user Django will use to make changes to the database. (This is what I changed, maybe you could try granting privileges to the specified user - didn't work for me).

    <password>: the user's password.

    <db_hostname_or_ip>: the IP address or hostname for the app - in development that would be localhost or 127.0.0.1

    <db_port>: the port number you'd like Django to play with while accessing the DB.

  2. Specify the database and schema on your migrations command

    Additionally, I had to add a database flag and specify the schema that Django would use to perform the migrations. It looked something like this:

    python manage.py migrate --database <db_schema>;

    Where <db_schema> is the database schema we'll be using with Django.

What's next? Well, more bugs.

I have realized I do not have an app design for the UI and inner workings of the app. The problem with this is that I keep making mistakes and do not even know what to Google to solve them.

So, I'll revert some changes and start with the app design process. I will be sharing the designs in the README file of the GitHub repo.

So yea, what's next is the app design process and seeing you next time.

Asalaam Aleykum!