﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36238	Migrate command executing project code cause migation failed.	jcyang		"I have an existing project with sqlite as database engine, and I want to recreate database file. 

So I just deleted existing db file and `migrations` folder,  and run command `python manage.py migate`. 

I got the this error:  `django.db.utils.OperationalError: no such table: django_content_type`.  

It confused me for a long time, util I noticed the following among the output messages.



{{{
  File ""<frozen importlib._bootstrap>"", line 1147, in _find_and_load_unlocked
  File ""<frozen importlib._bootstrap>"", line 690, in _load_unlocked
  File ""<frozen importlib._bootstrap_external>"", line 940, in exec_module
  File ""<frozen importlib._bootstrap>"", line 241, in _call_with_frames_removed
  File ""D:\workflow\backend\project\urls.py"", line 31, in <module>
    path('api/', include('api.urls')),
                 ^^^^^^^^^^^^^^^^^^^
  File ""C:\Python\Python311\Lib\site-packages\django\urls\conf.py"", line 39, in include
    urlconf_module = import_module(urlconf_module)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""C:\Python\Python311\Lib\importlib\__init__.py"", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ""<frozen importlib._bootstrap>"", line 1204, in _gcd_import
  File ""<frozen importlib._bootstrap>"", line 1176, in _find_and_load
  File ""<frozen importlib._bootstrap>"", line 1147, in _find_and_load_unlocked
  File ""<frozen importlib._bootstrap>"", line 690, in _load_unlocked
  File ""<frozen importlib._bootstrap_external>"", line 940, in exec_module
  File ""<frozen importlib._bootstrap>"", line 241, in _call_with_frames_removed
  File ""D:\workflow\backend\api\urls.py"", line 3, in <module>
    from api import handlers
  File ""D:\workflow\backend\api\handlers.py"", line 223, in <module>
    class PermissionHandler(_CRUD):
  File ""D:\workflow\backend\api\handlers.py"", line 233, in PermissionHandler
    syspermission_type = ContentType.objects.get(app_label='common',model='syspermission')
}}}

	
	
Apparently, Django executed the sevice code in my project file, and that led to the error because no databases available now.

I commented out the configuration `ROOT_URLCONF = 'project.urls'` to make it not execute the code in my project. And then `python manage.py migate` worked very well. Then I restored the  `ROOT_URLCONF = 'project.urls'` configuation item.

But that's just a bypass and weird way. 

Hope Django team could fix that. Thanks.



"	Uncategorized	closed	Uncategorized	5.1	Normal	invalid			Unreviewed	0	0	0	0	0	0
