tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
820 stars 94 forks source link

AttributeError: 'NoneType' object has no attribute 'pop' #165

Closed FIRDOUS-BHAT closed 3 years ago

FIRDOUS-BHAT commented 3 years ago

I was getting some error like this tortoise.exceptions.ConfigurationError: Can't create schema due to cyclic fk references while migrating the new schema changes. In order to get rid off from this error I removed aerich table from database and removed migrations folder as well now after initializing the migrations again with aerich init-db and aerich migrate, I'm now getting this error AttributeError: 'NoneType' object has no attribute 'pop' on line no. /aerich/migrate.py line 170, in diff_models old_models.pop(_aerich, None)

spacemanspiff2007 commented 3 years ago

I too deleted the database and now I am not sure how I can restore the functionality again. I still have the migration files but the aerich table is empty (it still does exist though).

How can I make aerich work again?

@FIRDOUS-BHAT Have you found a fix for your issue?

spacemanspiff2007 commented 3 years ago

@long2ice Would you be so kind and give me some pointers how I can restore the db entries from aerich? Maybe there is a fail save need that will restore the db entry based on the migration files?

long2ice commented 3 years ago

You can drop aerich table, delete migrations/{app} dir, and the rerun aerich init-db

spacemanspiff2007 commented 3 years ago

Thank you for your quick reply! I can do that - but won't this affect my production database? Because there the db table does already exist.

long2ice commented 3 years ago

That won't affect, aerich init-db only generate table create sql like create table if not exists..., on the safe side, you can review sql generated first.

spacemanspiff2007 commented 3 years ago

Thank you very much for your help!