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.
}
}
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
cd /home/sachin/Downloads/Django-1.4/DAMO/
Step4- Than Create the appname by using command given below
python manage.py startapp poll (appname is your database name like a poll)
Step5- Than After app creation done write code inside the models.py script like as a
from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
Step6- Then write the command for validating the models.py using thsi command given below
python manage.py validate
Step7- Than you check to the query works or not using this given below
python manage.py sqlall Person (Person is the table name)
Step8- Than useing this command to create table in your database
python manage.py syncdb
0 Comment(s)