I inherited a Django app without the migration files. I suppose the app was developed with an older Django version that the one on the server.
The first time python manage.py makemigrations is executed it is successful and produces 0001_initial.py file
Migration (python manage.py migrate) or new executions of makemigrations
with existent 0001_initial.py fail with a weird error:
File "/afat/afatprivate/AFATdashboard/migrations/0001_initial.py", line 223, in Migration
bases=(models.Model, AFATdashboard.models.__support),
AttributeError: module 'AFATdashboard.models' has no attribute '_Migration__support'
I searched for _Migration__support and found nothing useful.
The error is the same with an empty database too, so this related answer didn’t solve the problem
Code from 0001_initial.py, last line is 223
migrations.CreateModel(
name='EconCostoCorpiIdrici3',
fields=[
('waterbodycode', models.CharField(blank=True, db_column='waterBodyCode', max_length=255, null=True)),
('waterbodyname', models.CharField(blank=True, db_column='waterBodyName', max_length=255, null=True)),
('numinterventi', models.BigIntegerField(blank=True, db_column='numInterventi', null=True)),
('numinterventiconcosto', models.BigIntegerField(blank=True, db_column='numInterventiConCosto', null=True)),
('costocorpoidrico2227', models.DecimalField(blank=True, db_column='costoCorpoIdrico2227', decimal_places=65535, max_digits=65535, null=True)),
('coperturafinanziariacorpoidrico', models.DecimalField(blank=True, db_column='coperturaFinanziariaCorpoIdrico', decimal_places=65535, max_digits=65535, null=True)),
('percentualecoperturafinanziaria', models.DecimalField(blank=True, db_column='percentualeCoperturaFinanziaria', decimal_places=65535, max_digits=65535, null=True)),
('waterbodycostconfidence', models.DecimalField(blank=True, db_column='waterBodyCostConfidence', decimal_places=65535, max_digits=65535, null=True)),
('costocorpoidrico2227color', models.TextField(blank=True, db_column='costoCorpoIdrico2227Color', null=True)),
('recid', models.TextField(db_column='recId', primary_key=True, serialize=False)),
],
options={
'db_table': 'ECON_costo_corpi_idrici_3',
'managed': False,
},
bases=(models.Model, AFATdashboard.models.__support),
),
What can I do ?
UPDATE 1
My models.py starts this way:
class __support:
I’m wondering if support has become a keyword
Besides I’m testing a reduced model.py and I’m finding other errors. Most DecimalFields have these attributes:
decimal_places=65535, max_digits=65535
and I suspect these numbers are too high to be supported.
4
Reading the migration file it seems that the model you are using EconCostoCorpiIdrici3
has managed=False
which means that django will not create the db tables for it, it will create the migration files though. You can read more about the managed option on the docs
I guess you could remove the managed=False
and recreate the migrations
1
I have finally found a workaround.
At the beginning of models.py there is this class declaration:
class __support:
It begins with a double underscore, which turned out it has a special meaning in Django.
Lots of classes inherits from __support and inside the migration file 0001_initial.py the first one is that reported above, EconCostoCorpiIdrici3
bases=(models.Model, AFATdashboard.models.__support),
I replaced __support with _mySuperclass and the migration command was successful.
It was a trivial error which cost much time because there was no clue to its real cause.