Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create models in dijango

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 719
    Comment on it

    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

    1. DATABASES = {
    2.  
    3. 'default': {
    4.  
    5. 'ENGINE': 'django.db.backends.mysql ', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' , 'oracle'.
    6.  
    7. 'NAME': 'poll', # Or path to database file if using sqlite3.
    8.  
    9. 'USER': 'root', # Not used with sqlite3.
    10.  
    11. 'PASSWORD': 'root', # Not used with sqlite3.
    12.  
    13. 'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
    14.  
    15. 'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
    16.  
    17. }
    18.  
    19. }

    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

    1. cd /home/sachin/Downloads/Django-1.4/DAMO/

    Step4- Than Create the appname by using command given below

    1. 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

    1. from django.db import models
    2.  
    3. class Person(models.Model):
    4. first_name = models.CharField(max_length=30)
    5. last_name = models.CharField(max_length=30)

     

    Step6- Then write the command for validating the models.py using thsi command given below  

    1. python manage.py validate

    Step7- Than you check to the query works or not using this given below

    1. python manage.py sqlall Person (Person is the table name)

    Step8- Than useing this command to create table in your database

    1. python manage.py syncdb

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: