1
2
3
4
5
|
Operations to perform:
Apply all migrations: admin, auth, contenttypes, interface, sessions, usermana
ge
Running migrations:
No migrations to apply.
|
在django的db库里存在一张专门记录migrations的表”django_migrations”,通过查询可得出如下结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
mysql> select * from django_migrations;
+----+--------------+------------------------------------------+----------------------------+
| id | app | name | applied |
+----+--------------+------------------------------------------+----------------------------+
| 1 | interface | 0001_initial | 2017-03-07 09:34:26.118074 |
| 2 | contenttypes | 0001_initial | 2017-03-07 09:34:26.148074 |
| 3 | auth | 0001_initial | 2017-03-07 09:34:26.977426 |
| 4 | admin | 0001_initial | 2017-03-07 09:34:27.126923 |
| 5 | admin | 0002_logentry_remove_auto_add | 2017-03-07 09:34:27.167190 |
| 6 | contenttypes | 0002_remove_content_type_name | 2017-03-07 09:34:27.261077 |
| 7 | auth | 0002_alter_permission_name_max_length | 2017-03-07 09:34:27.306118 |
| 8 | auth | 0003_alter_user_email_max_length | 2017-03-07 09:34:27.391483 |
| 9 | auth | 0004_alter_user_username_opts | 2017-03-07 09:34:27.402682 |
| 10 | auth | 0005_alter_user_last_login_null | 2017-03-07 09:34:27.446044 |
| 11 | auth | 0006_require_contenttypes_0002 | 2017-03-07 09:34:27.450027 |
| 12 | auth | 0007_alter_validators_add_error_messages | 2017-03-07 09:34:27.466104 |
| 13 | auth | 0008_alter_user_username_max_length | 2017-03-07 09:34:27.514012 |
| 14 | sessions | 0001_initial | 2017-03-07 09:34:27.589340 |
| 15 | usermanage | 0001_initial | 2017-03-07 15:26:52.917539 |
| 16 | usermanage | 0002_auto_20170320_1429 | 2017-03-20 14:30:02.230243 |
+----+--------------+------------------------------------------+----------------------------+
16 rows in set (0.00 sec)
|
在表中id=1的记录中存在一个”interface 0001_initial”的操作记录,所以,当你删除所有migrations并新建”0001_initial.py”,执行migrate的时候就会出现上面的提示语;
解决方案(一):
进入到该django库后,删除id为1的记录;
1
|
delete
from django_migrations
where app=
' |
这里我们要删除的记录为:
1
|
delete
from django_migrations
where app=
'interface';
|
删除该app名字下的migrations下的除了init.py之外的文件
执行下面这两条命令:(在项目目录下)
1
2
|
python manage.py makemigrations
python manage.py migrate
|
再查询表”django_migrations”:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
mysql> select * from django_migrations;
+----+--------------+------------------------------------------+----------------------------+
| id | app | name | applied |
+----+--------------+------------------------------------------+----------------------------+
| 2 | contenttypes | 0001_initial | 2017-03-07 09:34:26.148074 |
| 3 | auth | 0001_initial | 2017-03-07 09:34:26.977426 |
| 4 | admin | 0001_initial | 2017-03-07 09:34:27.126923 |
| 5 | admin | 0002_logentry_remove_auto_add | 2017-03-07 09:34:27.167190 |
| 6 | contenttypes | 0002_remove_content_type_name | 2017-03-07 09:34:27.261077 |
| 7 | auth | 0002_alter_permission_name_max_length | 2017-03-07 09:34:27.306118 |
| 8 | auth | 0003_alter_user_email_max_length | 2017-03-07 09:34:27.391483 |
| 9 | auth | 0004_alter_user_username_opts | 2017-03-07 09:34:27.402682 |
| 10 | auth | 0005_alter_user_last_login_null | 2017-03-07 09:34:27.446044 |
| 11 | auth | 0006_require_contenttypes_0002 | 2017-03-07 09:34:27.450027 |
| 12 | auth | 0007_alter_validators_add_error_messages | 2017-03-07 09:34:27.466104 |
| 13 | auth | 0008_alter_user_username_max_length | 2017-03-07 09:34:27.514012 |
| 14 | sessions | 0001_initial | 2017-03-07 09:34:27.589340 |
| 15 | usermanage | 0001_initial | 2017-03-07 15:26:52.917539 |
| 16 | usermanage | 0002_auto_20170320_1429 | 2017-03-20 14:30:02.230243 |
| 17 | interface | 0001_initial | 2017-04-10 19:28:41.710626 |
+----+--------------+------------------------------------------+----------------------------+
16 rows in set (0.00 sec)
|
可发现已经新增一条”interface 0001_initial”的操作记录;