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

And run 'architect --module...' give me Import Error (Django) #57

Open
vncsms opened this issue Jan 31, 2019 · 6 comments
Open

And run 'architect --module...' give me Import Error (Django) #57

vncsms opened this issue Jan 31, 2019 · 6 comments

Comments

@vncsms
Copy link

vncsms commented Jan 31, 2019

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.

@dmitrykaramin
Copy link

Probably you firstly should try to import User model not directly but from get_user_model() from django.contrib.auth

@vncsms
Copy link
Author

vncsms commented Feb 1, 2019

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

@dmitrykaramin
Copy link

Try to avoid direct User import. Import from django.contrib.auth.models also not a good way.

@vncsms
Copy link
Author

vncsms commented Feb 1, 2019

But if cannot import with this two ways, how i import my model User?

@dmitrykaramin
Copy link

from django.contrib.auth import get_user_model
User = get_user_model()

@vncsms
Copy link
Author

vncsms commented Feb 1, 2019

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.

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

No branches or pull requests

2 participants