Django数据库迁移命令
Django数据库迁移
当使用Django创建好APP或修改了APP文件夹里头的models.py模型文件、admin.py后台注册文件等内容,在使用python manage.py runserver启动Django本地服务器之前,都应当对Django的项目中变动的数据迁移到数据库,Django自带的是sqlite3数据库。那么Django数据库迁移的命令如下:
python manage.py makemigrations
提示:该命令用于记录数据库迁移的记录;
python manage.py migrate
提示:该命令用于执行数据库的迁移。
如下内容为鄙人执行上述两个命令后,终端的输出:
(ml) MacBook-Pro:demo z$ python3 manage.py makemigrations
No changes detected
(ml) MacBook-Pro:demo z$ python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying sessions.0001_initial... OK