architect
architect copied to clipboard
And run 'architect --module...' give me Import Error (Django)
I add the partition configuration in my class:
@architect.install('partition', type='range', subtype='integer', constraint='100', column='id')
class Article(ArticleGeneric,
ConfidenceScoreModel,
EditableModel,
HitTrackedModel,
HotnessScoreModel,
VotableModel):
I export the path: $ export DJANGO_SETTINGS_MODULE=prisvo.settings
But when i execute architect partition --module article.models
Traceback (most recent call last):
File "/home/developer/.virtualenvs/prisvo/bin/architect", line 11, in <module>
sys.exit(main())
File "/home/developer/.virtualenvs/prisvo/local/lib/python2.7/site-packages/architect/commands/__init__.py", line 91, in main
orms.init()
File "/home/developer/.virtualenvs/prisvo/local/lib/python2.7/site-packages/architect/orms/__init__.py", line 17, in init
getattr(__import__(name, globals(), level=1), 'init', lambda: None)() # if yes, run init() for this ORM
File "/home/developer/.virtualenvs/prisvo/local/lib/python2.7/site-packages/architect/orms/django/__init__.py", line 7, in init
django.setup()
File "/home/developer/.virtualenvs/prisvo/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/developer/.virtualenvs/prisvo/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/developer/.virtualenvs/prisvo/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/developer/projects/prisvo/prisvo-backend/article/models.py", line 17, in <module>
from edition.base import EditableModel
File "/home/developer/projects/prisvo/prisvo-backend/edition/base.py", line 6, in <module>
from user.models import User
ImportError: No module named models
My site works with no problem, my model user work perfectly, my migrations are done without errors. Only here is giving me an error. And if i comment where the import is imported is give another import error with the same model but in another code.
Probably you firstly should try to import User model not directly but from get_user_model() from django.contrib.auth
Ok, i add django.contrib.auth.models import User
instead from user.models import User
. Now the commands architect partition --module article.models
works. But i cannot add users, because several errors. So i revert my import to from user.models import User
, and now works fine. I actually don't know what is happening, but i think my problem is solved. Thanks
Try to avoid direct User import. Import from django.contrib.auth.models
also not a good way.
But if cannot import with this two ways, how i import my model User?
from django.contrib.auth import get_user_model
User = get_user_model()
The problem is the django.contrib.auth.models import User
and from user.models import User
aren't the same, i have my own user model. And when i use django.contrib.auth
is not giving me my model. I think my error: ImportError: No module named models
it's happening because the conflict between another object that calls user. But in my project this conflict not occur, only when i execute the architect.