Execute the command after setting up database related things in models
python manage.py makemigrations
no errors here
execute again
python manage.py migrate
An error occurs
The error message is very long, look carefully to find the source of the error
django.db.utils.ProgrammingError: (1146, "Table 'test.model_stude
nt' doesn't exist")
The reason for this error is that I deleted a table in mysql by myself. When Django wanted to change the field, I found that the table was no longer there, so I reported an error--
The way to prevent recurrence is to modify the table through the settings in Django, do not delete the table in mysql by yourself
The solution is as follows:
1. Delete the tables created by yourself in mysql (except for the tables automatically generated by Django, delete the tables set by yourself due to business needs)
2. Find your own model, there is a folder named "migrations" in the directory, enter this folder
3. Keep the pycache folder and init file, and delete the rest
4. Find your database in mysql and find the table named "django_migrations"
5. Delete all data in the table
6. Re-execute the two commands
python manage.py makemigrations
python manage.py migrate Model
This database is normal!