django-oauth-toolkit
django-oauth-toolkit copied to clipboard
ValueError: The field oauth2_provider.AccessToken.application was declared with a lazy reference
Hi there,
I'm running makemigrations oauthy on Django==1.11 after extending AbstractApplication but with no success. I keep getting the error:
ValueError: The field oauth2_provider.AccessToken.application was declared with a lazy reference to 'oauthy.client', but app 'oauthy' isn't installed.
The field oauth2_provider.Grant.application was declared with a lazy reference to 'oauthy.client', but app 'oauthy' isn't installed.
The field oauth2_provider.RefreshToken.application was declared with a lazy reference to 'oauthy.client', but app 'oauthy' isn't installed.
Here is my models.py:
def content_file_name(instance, filename):
return '/'.join(['oauth', 'clients', str(instance.client_id), filename])
class Client(AbstractApplication):
logo = models.ImageField(u'logo', upload_to=content_file_name, null=True, blank=True)
I tried everything i've found on the web.. but most problems is about running migrate not makemigrations.
django-oauth-toolkit==1.0.0
oauthlib==2.0.6
Thanks in advance.
You first need to run a migration without your custom app model. Once the initial migration has been done, you can swap the default Application model for yours and your migration should succeed.
Thanks @rhymiz
I tried your advice and it worked. But now, i'm getting (1452, 'Cannot add or update a child row: a foreign key constraint fails (db.oauth2_provider_grant, CONSTRAINT oauth2_provider_grant_application_id_81923564_fk FOREIGN KEY (application_id) REFERENCES oauth2_provider_application (id))') when authorizing a client.
In settings.py you have something like the line below, correct? OAUTH2_PROVIDER_APPLICATION_MODEL='yourapp.Client'
How will this work in environments where application setup needs to be repeatable? For instance CI testing environments, etc.
@douglashall during the setup process in CI environments, you could use some sort of schema.sql file to create all the basic tables you need before any other migration and testing steps.
You first need to run a migration without your custom app model. Once the initial migration has been done, you can swap the default Application model for yours and your migration should succeed.
I think this breaks down on squashing migrations. What purpose does running an initial migration serve?
@iamhssingh I believe the initial version of toolkit did not have a swappable application model, so migrations needs to be applied in a specific order -- don't quote me on this, though.
I'm closing since I am unable to reproduce this. If you want to re-open Please create a gist that we can use to reproduce the issue.