about 9 years ago
To create models in dijango to following thses step in given below:
Step1- First you check your mysql is proparlly working in your systems.
Step2- Than DB setting in the settings.py in your project like as
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql ', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' , 'oracle'.
'NAME': 'poll', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'root', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql ', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' , 'oracle'.
'NAME': 'poll', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'root', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
Step3- Than create app name in your mysql database like database name is poll.
Step4- Than go to the path of your django project like as DAME
Step4- Than Create the appname by using command given below
Step5- Than After app creation done write code inside the models.py script like as a
Step6- Then write the command for validating the models.py using thsi command given below
Step7- Than you check to the query works or not using this given below
Step8- Than useing this command to create table in your database
0 Comment(s)