pythondjangodjango-tinymce

Uninstalling django-tinymce. Import error when makemigrations


Thanks for taking the time to read this.

I was not happy with TinyMCE extension in django and decided to switch to django-summernote. I first ran

pip uninstall django-tinymce

Removed all mentions of tinymce in the actual project.

Followed the instruction to install django-summernote. Upon completion I decided to run

python manage.py makemigrations
python manage.py migrate

to apply new extension, but get an error:

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'

I'm not sure why would Django care about what I did previously since I am simply asking to replace the editor. I can't run python manage.py runserver either.

I can't do anything before fixing this. I beg you guys, please help.

Note: I would ideally want to keep the contents of my current database.

Thanks for taking the time to read this.


Solution

  • Once you have removed all the mentions of tinymce from the models, admins and other files, you need to migrate using a special "flag":

    python manage.py makemigrations
    python manage.py migrate --fake-initial
    

    I am not to clear on the backend of this method, but it works. You can read more about it the official Django website: 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:

    1. 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.
    2. 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.