0% found this document useful (0 votes)
2 views

Database-setting-model-migrations

Uploaded by

POKemon Pokemon
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Database-setting-model-migrations

Uploaded by

POKemon Pokemon
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

step1:Create database in DBMS[mysql]

create database blog;

step2:Edit settings.py file for database setting.

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME':'blog',
'HOST':'localhost',
'USER':'root',
'PASSWORD':'',
}
}

if mysqlclient is not installed then need to install


mysqlclient by

pip install mysqlclient.

python <------>mysqlclient<-------->sql

Model=>M from MVT


================

Model:This is representative of table in database.

Model in Django = Table in Database.

No. of model in Django = No of Tables in Database.

tablename:post

id title sdesc det cat active

create table post(id int primary key auto_increment,


title varchar(50), sdesc varchar(50),
det varchar(200),cat int,active int);

Process to create table from django into database


=================================================
step1:open models.py file
step2:define class which is inherited from models.Model
this class become table in database.

step3:column names required in the table become data


members of the class defined in step2.

step4:
to define datatype of the columns or data members
there are some function or methods defined in
models module.

class Post(models.Model):
title=models.CharField(max_length=50)
sdesc=models.CharField(max_length=50)
det=models.CharField(max_length=300)
cat=models.IntegerField()
active=models.IntegerField()

step 5: Make migrations


Need to migrate table or class defined in models.py
to the dbms.

python manage.py makemigrations

when above command is executed, a migration file


is created in migrations folder of application folder.

step6: Migrate all migrations

python manage.py migrate

show tables;

desc blogapp_post;

You might also like