Start a django website using MySQL

Posted under » MySQL » Django updated on 12 April 2023

By now, you should have install venv and under this environment you have installed django.

Go to your webroot folder and

$ django-admin startproject students

If you intend to use apache then configure WSGI.

By default, Django is using SQLite as database. Right now the database is empty. If you intend to use MySQL then you need to start right.

Let us begin by creating a superuser.

While still under the venv environment, go the webroot folder

$ python createsuperuser --username=joe
django.db.utils.ProgrammingError: (1146, "Table 'bridev.auth_user' doesn't exist")

You may have this error. So create the auth tables

$ python migrate auth

Once the auth_user table is created you can try again. You will be prompted for a password. After you enter one, the user will be created immediately. If you leave off the --username or --email options, it will prompt you for those values.

You have 4 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, sessions.
Run 'python migrate' to apply them

If you are seeing this then you should already have installed MySQLclient and created database and user, added the mysql bit in and have ran this

$ sudo systemctl daemon-reload
$ sudo systemctl restart mysql

Now let us apply the migration.

$ python migrate

Now go the the website admin URL and see if you can log in as superuser.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data