7π
I think the problem is the database no longer sees a foreign key existing from the blogpost
table to the curationarticle
table. However, blogpost
still has a column called curation_article_id
which used to be used to store the id of the curationarticle
table.
Now when you try to run the migration, when Django loads information about the blogpost
table it only sees curation_article_id
as an IntegerField
instead of as a ForeignKey
. Django still allows you to attach on_delete
to the IntegerField
but the field itself does not have a SET_NULL
method which causes the error.
The fix would be to correct the database error.
Then hopefully you can figure out what caused the database anomaly in the first place.
There is a chance also that it has nothing to do with the database and that PyCharm as the middle man has confused itself.
The solution there might be to detach the database from PyCharm and reconnect.
54π
In my case I had removed a field but initially forgotten to change the unique_together Meta attribute leaving the removed field in there. Django obviously complained and I changed the unique_together but the migration came out with the migrations.RemoveField
before the migrations.AlterUniqueTogether
and I was getting this error.
After changing the order in the migration file from:
# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-11-04 15:00
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('team', '0021_auto_20161102_1930'),
]
operations = [
migrations.RemoveField(
model_name='csvideo',
name='youtube',
),
migrations.AlterUniqueTogether(
name='csvideo',
unique_together=set([('casestudy', 'platform', 'video_id')]),
),
]
to:
# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-11-04 15:00
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('team', '0021_auto_20161102_1930'),
]
operations = [
migrations.AlterUniqueTogether(
name='csvideo',
unique_together=set([('casestudy', 'platform', 'video_id')]),
),
migrations.RemoveField(
model_name='csvideo',
name='youtube',
),
]
β¦ the little beauty migrated.
Hope it helps someone
- Django: Check for related objects and whether it contains data
- In django, is aggregate(Count()) faster or better than .count() in anyway?
- Django-tables2 add button per row
- Correct way of transaction.rollback() with raise exception in django
4π
I had the exact same problem. This solved my issue:
If you defined on_delete='SET_NULL'
in model definition, replace with on_delete=models.SET_NULL
.
Then, look for other migrations which contain
field=models.ForeignKey( .... on_delete=b'SET_NULL' ....
and replace with
field=models.ForeignKey( .... on_delete=django.db.models.deletion.SET_NULL ....
Also, donβt forget to import the module: import django.db.models.deletion
0π
Some additional info for future readers of this threadβ¦
The resolution(trick) posted by @Rich Ross works, in in Django 2.0.6, for cases with the following traceback@migrations as well:
File "...\django\db\migrations\executor.py", line 117, in migrate
File "...\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
File "...\django\db\migrations\executor.py", line 244, in apply_migration
File "...\django\db\migrations\migration.py", line 122, in apply
File "...\django\db\migrations\operations\models.py", line 525, in database_forwards
File "...\django\db\backends\base\schema.py", line 358, in alter_unique_together
File "...\django\db\backends\base\schema.py", line 381, in _delete_composed_index
File "...\django\db\backends\base\schema.py", line 381, in <listcomp>
File "...\django\db\models\options.py", line 568, in get_field
raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
- Can not use celery delay for saved form: object is not JSON serializable
- Custom unique_together key name
- How do I implement markdown in Django 1.6 app?