Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs: how to use migrations on dango>1.7 with a custom application #227

Closed
synasius opened this issue Apr 6, 2015 · 6 comments
Closed
Labels

Comments

@synasius
Copy link
Contributor

synasius commented Apr 6, 2015

When using a custom application model migrations don't work out of the box.
The makemigrations command should fail with an error like:

ValueError: Lookup failed for model referenced by field oauth2_provider.Grant.application: foo.MyApp 

Let's say you have your custom user model in foo.MyApp, follow these steps to correctly create migrations for your app:

  1. Check you DON'T have OAUTH2_PROVIDER_APPLICATION_MODEL in your settings or it is commented out.
  2. Check both oauth2_provider and foo are listed in INSTALLED_APPS.
  3. Run makemigrations command
  4. Now add or uncomment OAUTH2_PROVIDER_APPLICATION_MODEL\
  5. Run migrate command.
@dustinfarris
Copy link
Contributor

Is this for someone who is a first-time user, or someone upgrading from Django < 1.7, or someone upgrading from DOT < 0.8?

@synasius
Copy link
Contributor Author

synasius commented Apr 7, 2015

You can reproduce the error with django>=1.7 and the current DOT master branch.

Create a new project, add an app with the custom application model and set the OAUTH2_PROVIDER_APPLICATION_MODEL in the settings.
Then try to run makemigrations and you'll get the error.

The steps above are the only workaround I'm aware of.

@femesq
Copy link

femesq commented May 12, 2015

@synasius Is the equivalent process necessary for those still using Django 1.6+South, or this issue is Django Migration (>1.7) issue?

@synasius
Copy link
Contributor Author

the issue occurs on a new Django>=1.7 project when using a custom application model.

Please note that changing the Application Model has the same effect of changing user model, so the same warnings applies. Please read https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#substituting-a-custom-user-model carefully!!

@mitchellrj
Copy link

It may be useful for people adding Django-OAuth-Toolkit to an existing project to be aware of run_before:

https://docs.djangoproject.com/en/1.9/howto/writing-migrations/#controlling-the-order-of-migrations

Any migration that adds a swappable application model should have:

run_before = [
    ('oauth2_provider', '0001_initial'),
]

specified in it.

@jleclanche
Copy link
Member

Closing this as 1.11 is the minimum version supported and it's been too long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants