0% found this document useful (0 votes)
24 views2 pages

Database Setting Model Migrations

Uploaded by

POKemon Pokemon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Database Setting Model Migrations

Uploaded by

POKemon Pokemon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

step1:Create database in DBMS[mysql]

create database blog;

step2:Edit [Link] file for database setting.

DATABASES = {
'default': {
'ENGINE': '[Link]',
'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 [Link] file
step2:define class which is inherited from [Link]
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([Link]):
title=[Link](max_length=50)
sdesc=[Link](max_length=50)
det=[Link](max_length=300)
cat=[Link]()
active=[Link]()

step 5: Make migrations


Need to migrate table or class defined in [Link]
to the dbms.

python [Link] makemigrations

when above command is executed, a migration file


is created in migrations folder of application folder.

step6: Migrate all migrations

python [Link] migrate

show tables;

desc blogapp_post;

You might also like