Let's say I have this model:
class Foo(models.Model):
name = models.CharField(max_length=255)
I want to rename it to Bar. What steps should I take? And how do I deal with The following content types are stale prompt?
Let's say I have this model:
class Foo(models.Model):
name = models.CharField(max_length=255)
I want to rename it to Bar. What steps should I take? And how do I deal with The following content types are stale prompt?
judy
On
Side note:
In some cases, when you change a model's name and then run python manage.py makemigrations, you'll see that the autogenerated migration is adding the new model and then deleting the old model (field by field, and then the model itself).
If that happens, then you may get this error when you try to run python manage.py migrate:
django.db.utils.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails')
To get around this issue: open up the autogenerated migration file and edit it manually, like so:
operations = [
migrations.RenameModel('Foo', 'Bar'),
]
Then run the python manage.py migrate again.
Copyright © 2021 Jogjafile Inc.
In my particular case it was like so:
./manage.py makemigrations.django_content_typetable. Deal with them accordingly.Inspect your database for references from Django tables. Most likely that would be:
In my case I had no records in
django_admin_log,auth_group_permissions,auth_user_user_permissions.Run
./manage.py migrate. When it asks:You can answer
yesonly if you have no records referencing records infootable in the three tables mentioned above. Or if losing them is not an issue for you.