Reputation:
I am altering an existing application so I can expand the use case a bit. I have already created a new model and altered the view and template a bit. Now I want to run migrations, but I keep getting the NameError and a Google search didn't provide me with much more information, especially since I am adding things to a working application rather than creating something from scratch. Is anyone able to help me?
I have added the following line to admin.py: admin.site.register(InputData)
the error:
C:\var\www\SYSTEM>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\registry.py", line 120, in populate
app_config.ready()
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\admin\apps.py", line 24, in ready
self.module.autodiscover()
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\var\www\SYSTEM\System\service_development\admin.py", line 201, in <module>
admin.site.register(InputData)
NameError: name 'InputData' is not defined
EDIT: I have solved it myself. Turns out there was an 'init' file where all models had to be referenced in order to use them in Admin.
Upvotes: 0
Views: 5888
Reputation: 181
The last two lines of your error give me the idea that you might have forgotten to import 'InputData' class in admin.py file.
File "C:\var\www\SYSTEM\System\service_development\admin.py", line 201, in <module>
admin.site.register(InputData)
NameError: name 'InputData' is not defined
Import 'InputData' class in admin.py and you are good to go :)
Upvotes: 2
Reputation: 1991
This most likely means that you are not importing "InputData" in your admin.py file.
Upvotes: 5