This is my reference notes

python -m django –version

django-admin startproject mysite

python runserver

-Views – Controller – Model Validation on the server side
-Templates – Views (Models Validation on the Client Side) – Javascript disabled – Submit add the following connection string as default.
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: ‘northwind’,
‘USER’: ‘developer’,
‘PASSWORD’: ‘Kingdom’,
‘HOST’: ‘’,
‘PORT’: ‘3306’,
-Run this command to install the mysql client globally using pip.
pip install mysqlclient
Admin App
-Register all models in the Admin app.
-Master data entry should be done via App.
-All master data tables must start with ref_

    -Foreign key relationships must be maintained
    -Migrations must be used so that db deployment is done in correct steps as per the dependency.
    -Models additional validation must be done via validators

Production deployment must have a new secret key in the project’s
Project’s should have the url entries for all applications otherwise we will get 404.

After the project is created run the following command and see the default homepage at this location.
python runserver

Step2 : Admin site setup and users management

Before creating any apps migrate admin models to database using the following command.
python migrate
Create a superuser using the following command.
python createsuperuser
Run the following query against the auth_user table to see if the superadmin is created successfully
SELECT * FROM djangotutorial.auth_user;
NOTE: After deployment to production. Ask the client to change password for the superadmin via admin app. **
Login to admin portal and enter first name and last name of the super admin if you want.
Create all the roles needed for your applications in the admin portal.
Grant required permission to all roles

Give additional permissions to users in addition to roles permissions

App Creation and Models Creation and Data Entry for Ref tables.

Create an app under this project using the following command.
python startapp cruddemo
Add to the app folder and initialize the app name as shown below
from . import views
from django.urls import path
app_name = ‘cruddemo’
Create a sample table ref_record_status in Mysql and run the following command to generate python model class.
python inspectdb > output.txt
Copy only the models that your application needs from the output.txt file to in your app.
Register the model in the admin portal.
in of the app add the following lines. Copy the model name from file.
from .models import RefRecordStatus
In project add the following entry in INSTALLED_APPS
Run the following command and login to the admin portal.
Add data to the reference tables via GUI.
TODO: Generate python code for migrating initial data also. **

Step 4: Deploying the database objects from admin and app to new database.

  1. Create a new database and update the name of the database in default connection string.
  2. Run this command to migrate all the admin objects.
    python migrate
  3. To migrate the objects of the applications run the following command.
    python makemigrations cruddemo
    python sqlmigrate cruddemo 0001
    python migrate

This did not work. **We need to solve it in the future.