cfpb / django-flags

Feature flags for Django projects
https://cfpb.github.io/django-flags/
Creative Commons Zero v1.0 Universal
260 stars 32 forks source link

Using django-flags with migrate_schemas #85

Open Vinci08 opened 2 years ago

Vinci08 commented 2 years ago

Hi, Our django app uses django-tenant-schemas, thus we need to use migrate_schemas instead of migrate. I followed your user guide except for the migrate step, and always got the error below when click flagstate in django admin panel. I have researched this issue for couple hours, but there was very little info on this. I'd like to know if django-flags support migrate_schemas? That way I can understand the source of our problem.

Thank you!

`

ProgrammingError at /admin/flags/flagstate/add/

relation "flags_flagstate" does not exist
LINE 1: ...state"."value", "flags_flagstate"."required" FROM "flags_fla...
                                                             ^
Request Method: | GET -- | -- http://127.0.0.1:8000/admin/flags/flagstate/add/ 2.0.5 ProgrammingError relation "flags_flagstate" does not exist LINE 1: ...state"."value", "flags_flagstate"."required" FROM "flags_fla...

`

willbarton commented 2 years ago

Hi @Vinci08. I'm not familiar with django-tenant-schema, so I don't know right off what it's doing that might be different from Django's standard migrate. With a glance at the documentation, it looks like migrate_schemas should call migrate. There's nothing I can see right off that suggests django-tenant-schema can't work with django-flags. The lack of the relation suggests that the django-flags models aren't getting migrated correctly however.

I wonder, where do you have the "flags" app included in the various _APPS settings that django-tenant-schema provides? My suspicion would be something to do with this — the "flags" migrations aren't getting run, and if django-tenant-schema is using these settings to determine which apps to migrate, that would suggest it needs to be included in one or more of them.

I will note too, if there are particular changes that would make django-flags work with multi-tenancy Django, we'd happily accept them!

Vinci08 commented 2 years ago

Hi @willbarton , thank you for taking your time and looking into this issue!

I included flags in both shared_app and installed_app, but the problem remained the same. Even though django would say flags being migrated with 00012 and 00013 migration files, no table was actually created in the database. Would this be something to do with the Middleware?

Edit: i double checked django-migration tables in both production and public database. Neither showed any row with app_name = flags. Run migration will just show no migration to run or no change in the app "flags".