#36238: Migrate command executing project code cause migation failed.
------------------------+-----------------------------------------
     Reporter:  jcyang  |                     Type:  Uncategorized
       Status:  new     |                Component:  Uncategorized
      Version:  5.1     |                 Severity:  Normal
     Keywords:          |             Triage Stage:  Unreviewed
    Has patch:  0       |      Needs documentation:  0
  Needs tests:  0       |  Patch needs improvement:  0
Easy pickings:  0       |                    UI/UX:  0
------------------------+-----------------------------------------
 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.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36238>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/010701957ab58e98-939bd896-209d-4926-9082-dbbfcd3402c7-000000%40eu-central-1.amazonses.com.

Reply via email to