卸载 django-tinymce。 makemigrations导入报错
Uninstalling django-tinymce. Import error when makemigrations
感谢您花时间阅读本文。
我对 django 中的 TinyMCE 扩展不满意,因此决定切换到 django-summernote。我先运行
pip uninstall django-tinymce
删除了实际项目中所有提及tinymce的内容。
按照说明安装 django-summernote。完成后我决定 运行
python manage.py makemigrations
python manage.py migrate
应用新扩展,但出现错误:
File "/Users/rasulkireev/Sites/dj-pw/now/migrations/0006_auto_20190703_0134.py", line 4, in <module>
import tinymce.models
ModuleNotFoundError: No module named 'tinymce'
我不确定为什么 Django 会关心我之前所做的事情,因为我只是要求更换编辑器。我也不能 运行 python manage.py runserver
。
在解决这个问题之前我无能为力。求求各位大侠帮忙
注意:我希望保留当前数据库的内容。
感谢您花时间阅读本文。
从模型、管理员和其他文件中删除所有提及 tinymce 的内容后,您需要使用特殊的 "flag":
进行迁移
python manage.py makemigrations
python manage.py migrate --fake-initial
我不是很清楚这个方法的后端,但它确实有效。您可以在 Django 官方网站上阅读更多相关信息:
https://docs.djangoproject.com/en/2.2/topics/migrations/
This will make a new initial migration for your app. Now, run python
manage.py migrate --fake-initial, and Django will detect that you have
an initial migration and that the tables it wants to create already
exist, and will mark the migration as already applied. (Without the
migrate --fake-initial flag, the command would error out because the
tables it wants to create already exist.)
Note that this only works given two things:
- You have not changed your models since you made their tables. For
migrations to work, you must make the initial migration first and
then make changes, as Django compares changes against migration files, not the database.
- You have not manually edited your database - Django won’t be able to detect that your database doesn’t match your models, you’ll just get errors when migrations try to modify those tables.
感谢您花时间阅读本文。
我对 django 中的 TinyMCE 扩展不满意,因此决定切换到 django-summernote。我先运行
pip uninstall django-tinymce
删除了实际项目中所有提及tinymce的内容。
按照说明安装 django-summernote。完成后我决定 运行
python manage.py makemigrations
python manage.py migrate
应用新扩展,但出现错误:
File "/Users/rasulkireev/Sites/dj-pw/now/migrations/0006_auto_20190703_0134.py", line 4, in <module>
import tinymce.models
ModuleNotFoundError: No module named 'tinymce'
我不确定为什么 Django 会关心我之前所做的事情,因为我只是要求更换编辑器。我也不能 运行 python manage.py runserver
。
在解决这个问题之前我无能为力。求求各位大侠帮忙
注意:我希望保留当前数据库的内容。
感谢您花时间阅读本文。
从模型、管理员和其他文件中删除所有提及 tinymce 的内容后,您需要使用特殊的 "flag":
进行迁移python manage.py makemigrations
python manage.py migrate --fake-initial
我不是很清楚这个方法的后端,但它确实有效。您可以在 Django 官方网站上阅读更多相关信息: https://docs.djangoproject.com/en/2.2/topics/migrations/
This will make a new initial migration for your app. Now, run python manage.py migrate --fake-initial, and Django will detect that you have an initial migration and that the tables it wants to create already exist, and will mark the migration as already applied. (Without the migrate --fake-initial flag, the command would error out because the tables it wants to create already exist.)
Note that this only works given two things:
- You have not changed your models since you made their tables. For migrations to work, you must make the initial migration first and then make changes, as Django compares changes against migration files, not the database.
- You have not manually edited your database - Django won’t be able to detect that your database doesn’t match your models, you’ll just get errors when migrations try to modify those tables.