시리아아
30
2021-02-26 19:06:14 작성 2021-02-26 20:24:14 수정됨
5
170

django migrate가 안됩니다


makemigrations는 되는데 migrate를 하면 No migrations to apply. 적용할게 없다고 나오고 웹 실행하면 또 이렇게 테이블이 없다고 오류나고... 어쩌란건지 모르겠습니다 ㅠㅠ 도와주세요
init 파일만 제외후 삭제하고 migrate를 해봐도 django.db.utils.OperationalError: no such table: pybo_comment라고 나옵니다.. 

 

Environment:

Request Method: POST

Request URL: http://127.0.0.1:8000/pybo/comment/create/303


Django Version: 3.1.7

Python Version: 3.8.5

Installed Applications:

['django.contrib.admin',

 'django.contrib.auth',

 'django.contrib.contenttypes',

 'django.contrib.sessions',

 'django.contrib.messages',

 'django.contrib.staticfiles',

 'pybo.apps.PyboConfig',

 'commom.apps.CommomConfig']

Installed Middleware:

['django.middleware.security.SecurityMiddleware',

 'django.contrib.sessions.middleware.SessionMiddleware',

 'django.middleware.common.CommonMiddleware',

 'django.middleware.csrf.CsrfViewMiddleware',

 'django.contrib.auth.middleware.AuthenticationMiddleware',

 'django.contrib.messages.middleware.MessageMiddleware',

 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Traceback (most recent call last):

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\backends\utils.py", line 84, in _execute

    return self.cursor.execute(sql, params)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\backends\sqlite3\base.py", line 413, in execute

    return Database.Cursor.execute(self, query, params)


The above exception (no such table: pybo_comment) was the direct cause of the following exception:

  File "C:\Anaconda3\envs\django\lib\site-packages\django\core\handlers\exception.py", line 47, in inner

    response = get_response(request)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response

    response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File "C:\Users\user\Desktop\django\projects\mysite\pybo\views.py", line 152, in comment_create_question

    comment.save()

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\models\base.py", line 753, in save

    self.save_base(using=using, force_insert=force_insert,

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\models\base.py", line 790, in save_base

    updated = self._save_table(

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\models\base.py", line 895, in _save_table

    results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\models\base.py", line 933, in _do_insert

    return manager._insert(

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\models\manager.py", line 85, in manager_method

    return getattr(self.get_queryset(), name)(*args, **kwargs)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\models\query.py", line 1254, in _insert

    return query.get_compiler(using=using).execute_sql(returning_fields)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\models\sql\compiler.py", line 1397, in execute_sql

    cursor.execute(sql, params)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\backends\utils.py", line 98, in execute

    return super().execute(sql, params)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\backends\utils.py", line 66, in execute

    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers

    return executor(sql, params, many, context)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\backends\utils.py", line 84, in _execute

    return self.cursor.execute(sql, params)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\utils.py", line 90, in __exit__

    raise dj_exc_value.with_traceback(traceback) from exc_value

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\backends\utils.py", line 84, in _execute

    return self.cursor.execute(sql, params)

  File "C:\Anaconda3\envs\django\lib\site-packages\django\db\backends\sqlite3\base.py", line 413, in execute

    return Database.Cursor.execute(self, query, params)


Exception Type: OperationalError at /pybo/comment/create/303

Exception Value: no such table: pybo_comment



0
  • 답변 5

  • 니르바나
    2k
    2021-02-26 20:04:27
    Db삭제
    Init파일빼고 나머지 마이그레이션 파일 삭제후 처음부터 해보세요.
  • 시리아아
    30
    2021-02-26 20:18:57

    삭제하고 다시 makemigrations , migrate 를 해보아도 똑같습니다 ㅠ

    django.db.utils.OperationalError: no such table: pybo_comment

  • 니르바나
    2k
    2021-02-26 20:24:58

    migrations폴더에 있는 파일도 다 삭제하셨어요?

  • 니르바나
    2k
    2021-02-26 20:31:06
    다 삭제하고 makenigration만 한번치고 나온 파일 내용 올려보세요
  • 시리아아
    30
    2021-02-27 13:34:03 작성 2021-02-27 13:35:57 수정됨

    Migrations for 'pybo':
    pybo\migrations\0001_initial.py

        - Create model Answer

        - Create model Question

        - Create model Comment

        - Add field question to answer


    입니다!

  • 로그인을 하시면 답변을 등록할 수 있습니다.