1. Delete a table in the database and re-execute Python manage Error in py migrate, prompting that this table does not exist.
2. This is mainly because Django usually creates a new table during the first migration, and the subsequent tables will not create a new table, but only check the changes of fields. Therefore, since we have deleted this table, Django will naturally report an error when checking the changes of fields in this table.
3. The solution is still to execute Python manage Py makemigrations and python manage Py migrate only deletes the record of the table created during the first migration before executing this. Otherwise, it detects that it has been executed for the first time, and the table will not be created later.
(1) In the app module, there is a migrations folder. Except for the first two files, other files are deleted. In fact, every time there is a change, a file will be generated here. The following 001_initial.py is generated during the first migration according to its name. That is, because it exists, no table will be created every time it is executed in the future.
(2) Secondly, there are corresponding records in the database, which should also be deleted. Let’s take a closer look at what is stored in the database. In django_migrations, this table stores records of each migration. Of course, what module is recorded and the corresponding file name. For example, our module here is dtheme, and the file here is 001_initial, which is similar to ours There are one-to-one correspondence in the folder. Similarly, delete this record.
4. Then execute Python manage Py makemigrations and python manage Py migrate is OK. It should be noted that if there are other models under the app module, the tables created by other models should also be deleted, which is equivalent to that our solution is for the whole app module, and all tables will be regenerated if they need to be executed, otherwise some existing errors will be prompted.
Similar Posts:
- [Solved] Django Error: – no such table: main.auth_user__old
- [Solved] DjangoORM Run python manage.py makemigrations Error: no changes detected
- [Solved] Djiango Create Migrations Error: query = query.decode(errors=’replace’) AttributeError: ‘str’ object has no attribute ‘decode’
- [Solved] You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for…
- [Solved] NodeNotFoundError(self.error_message, self.key, origin=self.origin) django.db.migrations.excep
- Solutions to typeerror: expected string or bytes like object error
- How to Solve Django Error: No such column: xxx
- [Solved] Django database Modify Warning: Did you rename house.houseid to house.id (a BigAutoField)? [y/N] n
- [Django] python manage.py syncdb Unknown command: ‘syncdb’
- Error: Unknown column ‘*_image_url’ in ‘field list’ [How to Solve]