4. Most probably you need a database for the Django Project
To use MySQL with this Django App:
(For a very detailed “How to install MySQL 8 on Windows Server 2016” see my other post.)
Download the MySQL installer from here: https://dev.mysql.com/downloads/installer/
I prefer downloading the larger package listed here. I find it better to have a full snapshot of the installer used during setup. The latest version, at the time of this writing, is MySQL 8.0.15 (MySQL 8.0.11 has known bugs!). The smaller ~15MB file eventually downloads the main MySQL installer while finishing the steps.
Double-click MySQL 8 from the executable
.msifile.Goto custom settings and select the Python connector.
Set up a root password (Make a note of the Password at a safe place).
Login to MySQL as superuser:
mysql -u <superuser> -pCreate Database:
CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;Create a DB User with Password:
mysql> CREATE USER '<DATABASE_USER>'@'localhost' IDENTIFIED BY '<DATABASE_PASSWORD>';Grant permissions to user for the database:
mysql> GRANT ALL PRIVILEGES ON <DATABASE_NAME>.* TO '<DATABASE_USER>'@'localhost';Then, if you have a MySQL dump file, import the database into MySQL:
mysql -u DATABASE_USER_ID -p <DATABASE_NAME> < db_dump_file.sqlIf you don’t have a MySQL database dump file, initialise a fresh set of database tables (See the following section).
Make sure the Django Projects
settings.pyfile contains the settings to connect to the MySQL database (See: https://docs.djangoproject.com/en/2.1/ref/settings/#std:setting-DATABASES)
(Optionally you can set up PhpMyAdmin to manage the MySQL database via UI.)
(Note: In my testing, I found that MySQL was rather slow on Windows, so do consider the Database choice well. That’s beyond the scope of this article but I encourage you to research it a bit.)
(Note: The steps for PostgreSQL would be similar, with minor changes to the commands.)
To use SQLite3 with this Django App:
It’s quite simple to work with SQLite3, as you don’t have to configure the Database Name, DB User, Password, etc.
Just download a pre-compiled SQLite3 binary from https://sqlite.org/download.html. Make sure sqlite is in your PATH variable.
Then, you simply need the SQLite3 database file and make sure the Django Projects settings.py file contains the settings to connect to the Sqlite3 database (https://docs.djangoproject.com/en/2.1/ref/settings/#std:setting-DATABASES) or initialise a fresh SQLite3 database using the following steps.
To Initialise Fresh Tables in the Database (if a database dump isn’t available):
Activate Virtual Environment
cd into the project code directory.
Generate migration files for all your Django Apps one by one
python manage.py makemigrations <your_django_app-1>python manage.py makemigrations <your_django_app-2>etc.Run the migrate command, which runs the migration scripts generated in previous step.
python manage.py migrateCreate a superuser account. Make a note of the username/Password.
python manage.py createsuperuser
Last updated