AttributeError: module 'factory' has no attribute 'django'
See original GitHub issueDescription
I cannot import the DjangoModelFactory as described in the documentation. I am using factory_boy 3.0.0 and python 3.8.3:
->pip freeze | grep factory
factory-boy==3.0.0
->python --version
Python 3.8.3
To Reproduce
From the documentation, https://factoryboy.readthedocs.io/en/3.0.0/orms.html I tried to create a class:
import factory
class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = 'myapp.User' # Equivalent to ``model = myapp.models.User``
django_get_or_create = ('username',)
I get the following error:
AttributeError: module 'factory' has no attribute 'django
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Python import error "module 'factory' has no attribute 'fuzzy'"
When you import a Python module (your import factory ), you can then access directly what is declared in that module (e.g factory.Factory...
Read more >factory.django — Factory Boy rbarrois-guide documentation
__name__)) try: manager = model_class.objects except AttributeError: # When inheriting from an abstract model with a custom # manager, the class has no...
Read more >Improve your Django tests with fakes and factories - HackSoft
Improve your Django tests with fakes and factories: Advanced usage ... AttributeError: 'Roster' object has no attribute 'start_after'.
Read more >AttributeError: 'module' object has no attribute '_handlerList'
As I suspected, there is a problem with the logging module, which is probably shadowed, i.e. when Django performs "import logging" it imports...
Read more >Run.py error; module 'collections' has no attribute 'Iterable'
... "C:\Program Files\MongoDB\M220P\mflix-python\mflix\factory.py", line 12, ... Iterable)): **AttributeError: module 'collections' has no ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also I want to point out that https://github.com/FactoryBoy/factory_boy/commit/7a2d57778f1d8167cbcfb2cf6d61558d7ee39abf does not work.
This imports the “real django” pkg instead of the
django.py
of factoryboy. I believe the line should befrom . import django
?See https://github.com/FactoryBoy/factory_boy/blob/master/docs/changelog.rst#300-2020-08-12, you need to rewrite your imports.