Opened 8 years ago
Closed 8 years ago
#26752 closed Bug (duplicate)
RenameModel requires camel case model names
Reported by: | Neil Parsons | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The migrations.RenameModel
class appears to accept all lowercase model names but when the makemigrations
command is run afterwards it will generate an AlterField
migration every time. This occurs when there exists a model that has a ForeignKey
that relies on the renamed model.
When the model names are changed to camel case the makemigrations
command works as expected and no longer generates AlterField
migrations.
Migration that will cause the error case:
migrations.RenameModel( old_name='originalmodel', # Note: Not using CamelCase! new_name='renamedmodel', ),
The generated migration in the error case:
migrations.AlterField( model_name='anothermodel', name='foreign_key_field', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='an_app.RenamedModel'), ),
This behaviour can be seen in this demo project: https://github.com/npars/django-bad-migrations
Probably the same cause as #23916.