5π
Try using RenameModel
and RenameField
. See answer here: https://stackoverflow.com/a/26241640/57952
15π
For me, this error occurred, because I was swapping a ForeignKey Model from
my_field = models.ForeignKey('old.model', ...)
to
my_field = models.ForeignKey('new.model', ...)
The solution was to edit the resulting migration manually, and add the latest migration from the new
app as a dependency:
class Migration(migrations.Migration):
dependencies = [
('old', '0016_whatever'),
('new', '0002_latest_migration'), # Add this line
]
- [Django]-Cannot resolve 'django.utils.log.NullHandler' in Django 1.9+
- [Django]-Get last record in a queryset
- [Django]-Custom QuerySet and Manager without breaking DRY?
1π
I just had this again on the latest django. A shared model was renamed (but not moved to a new app), and the issue was that it failed to pick up one of the other apps that was referencing it.
I canβt see why it had an issue with just one app but not the others. The initial makemigraitons
went fine, so it just needed to be added to the migration file it created. After that, subsequent calls to makemigrations
return "no changes detected", as it should be.
# Generated by Django 3.2.5
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
# all the following apps were correctly added as dependencies
('supplier', '0001_initial'),
('marketing', '0004_add_some_field'),
('devops', '0002_fix_some_model'),
('sales', '0001_initial'),
('warehouse', '0010_set_trained'),
('products', '0005_change_sku_format'),
('search', '0003_remove_bad_data'),
# Manually add this one, for the app that was missed
('left_out', '0007_change_name'),
]
operations = [
migrations.RenameModel(
old_name='OldModelName',
new_name='NewModelName',
),
]
- [Django]-How can I avoid "Using selector: EpollSelector" log message in Django?
- [Django]-Django rest framework β filtering for serializer field
- [Django]-How to cache Django Rest Framework API calls?
-5π
delete the entire migration folder and then create it again with the __init__.py
file and thank me later.
- [Django]-Django's self.client.login(β¦) does not work in unit tests
- [Django]-Django Forms: pass parameter to form
- [Django]-Django not sending emails to admins