-
Notifications
You must be signed in to change notification settings - Fork 103
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
Error when running migration script: more than one primary key #115
Comments
The following workaround results in a working admin app:
Is there supposed to be a migration script? (Django complains if I don't create one.) |
This leads me to ask: should my ldapdb models be triggering the creation of migration scripts, or am I doing something wrong? |
migrate
: more than one primary key
migrate
: more than one primary key
@kwill The answer is "don't create migrations"; Django should not complain about them. The The fix would be to never call |
Thanks for the info. I have other models in |
Oww. That's an option I'll have to consider — maybe I could be able to bypass the migration generator and either not generate any migration code, or silently skip the migration methods. I'll add this to the todo-list for version 0.9.0. |
Any progress with this? Although workaround works i think it's not a best idea to manually edit migration files (;) With one exception: next |
Is this a sqlite3 specific problem? |
@MarcPuckett its been a while, if I recall correctly, I ran into this issue with a mysql database backend. |
I'm not sure if I'm addressing the same issue, but I think I ran into this before I realized that I needed to run the migrations. When I'd just runserver and execute a view, I would get errors about multiple PKs. So I went through the django-ldapdb code and saw that the base model has At first I grimaced and figured I could hack my way around this, as I wanted to make my organizations |
How about adding Options.managed = false to ldapdb.Model class ?
It solve problem with more than one primary key for me. |
@DreamerDDL I've tried this and I kept hitting issues. The approach that I'm using now is by overriding the router with my own implementation which has a different version of The current version checks for an attribute called base_dn. This is however not present when executing migrations as Django introduces fake migration objects in some cases during migration. I also could not find any identifier on the fake model object which clearly identifies the fact that it is an ldap model. That's why I've implemented is_ldap_model like this: from ldapdb.models import Model as LdapModel
from django.apps import apps
def is_ldap_model(model):
real_model = apps.get_model(
model._meta.app_label,
model._meta.model_name
)
return issubclass(real_model, LdapModel) This implementation depends on the current models present in the codebase. This may have implications. However I don't see a better solution right now. Also important to know is that the if the router says that Django should not allow migrations it will still generate migrations. It only will skip them in execution! |
@rbarrois, I am new to django-ldapdb but find it quite nice. However I am also getting the issue mentioned here and the fix mentioned by @Ecno92 in #115 (comment) works well! Is there a reason why this has not been implemented yet within the last year? Or is it only me who is still having this issue? I'm happy to create the necessary PR if you're okay with it. |
Fixed in #201 |
Steps to reproduce:
makemigrations
migrate
runserver
What should happen:
What happens instead:
migrate
(see below)runserver
or visit admin appConfiguration:
settings.py (points to Online LDAP Test Server)
models.py
admin.py
0003_ldapgroup.py (autogenerated)
The text was updated successfully, but these errors were encountered: