Database migration in django

Django is a web development framework written in python. Its characteristics are:

  1. Heavyweight framework, with many functional components encapsulated inside, making development easier and faster,

  2.MVT mode: front-end and back-end separation, high cohesion and low coupling, m: model, the same function as m in mvc, responsible for interacting with the database, data processing, v: view, the same function as c in mvc, receiving requests , Perform business processing, and return a response, t:template, which has the same function as v in mvc, and is responsible for encapsulating and constructing the returned html.

orm: Object-relational mapping, which mainly implements the mapping of model objects to database data.

1. First, create a model class in, example:

2. In the file, add the configuration item to the sub-application where is located, otherwise the orm database will not be able to identify it

 3. Register the model class in

4. Next is the command for database migration

  python migrate # Generate the corresponding SQL statement according to the database migration file and execute it
  # In the first execution, in order to create the database required by the default Django first
  python makemigrations # Create database migration file
  # This execution is to create the app The migration file of the class model class
  # Generate the corresponding SQL and execute the newly added model class migration file, and actually create the corresponding table

The default database in Django is sqlite3

 Sqlite is a lightweight database that takes up very little resources, about a few hundred kilobytes of memory is enough, it can support mainstream operating systems such as windows/linux/unix, and a complete database stored in a disk file is more popular than some The database should be fast, simple and easy to operate in most common databases. APIs are independent: no additional dependencies, support for multiple development languages, stored locally in binary form, better performance when the load is less than 100,000, and save Remote connections to the database server will be even faster.

This article is reprinted from:

Leave a Reply