Python 2.7.6
Django1.8.3
IDE Eclipse+pydev
The Django development model is the MTV (c) mode (model, template, view (URLs)).
For the model I understand that each of the classes in the App.models corresponds to the table of each database, and models is the main definition of a table, interacting with the database, the data to be added and censored, and so on, which is the core of a site storage data.
To create a good models first to build a database, if you want to use the database is SQLite, then you do not need to set up, if you want to use a database such as MySQL, You need to set setting.py, a dictionary of databases in setting.py, as follows (I'm using MySQL)
DATABASES = {
' Default ': {
' ENGINE ': ' Django.db.backends.mysql ',//If you are using SQLite user and the following three lines are not required
' Name ': ' Hello ', (Hello is the name of the database)
"User": "User",
"PASSWORD": "PASSWORD",
"HOST": "",
"PORT": "",
}
}
After setting up the database, you also need to create a database corresponding to the app, and the database name is the value corresponding to ' name ' above.
To create a MySQL database named Hello in the terminal, enter it in the terminal:
Msql-u user-pxxxxxxxxcreate Databases Hello
The database is created
Then click on the project you want to work with in eclipse right-select Django make migration migrate you have successfully created a table
You can enter it at MySQL Terminal:
Use helloshow tables
You can see the database table you just created
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Django Development (II) "Models"