OperationalError:没有这样的表

时间:2016-10-10 17:45:10

标签: django sqlite migration django-migrations

所以我正在开发我的应用程序并为我的模型添加了一个slugfield。然后正常情况继续前进到var time=window.document.getElementById('time'); //time is element <div id="time"></div> showing the time var st; //show time video.ontimeupdate=function(){ ct=parseInt(video.currentTime); //ct is current time if(st!=ct) //little effort to optimize processing and showing the time { st=ct; var hours=parseInt(st/3600); var minutes=parseInt((st%3600)/60); var seconds=parseInt(st%60); if((''+minutes).length==1)minutes='0'+minutes; if((''+seconds).length==1)seconds='0'+seconds; time.innerHTML=''+hours+':'+minutes+':'+seconds; } }; ,并出现了一道巨大的红墙错误。

makemigrations

我试图删除我添加的字段但没有用。我已经做了很多在stackoverflow上建议的事情。

我也忘了将项目添加到github,现在也没有原始数据库文件。

似乎给出错误的模型:

Traceback (most recent call last):
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\backends\sqlite3\base.py", line 337, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: Reader_manga

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 2016.2.3\helpers\pycharm\django_manage.py", line 41, in <module>
    run_module(manage_file, None, '__main__', True)
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python35-32\lib\runpy.py", line 182, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python35-32\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python35-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:/WindowsFolders/Documents/Python/ReaderProject\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\core\management\__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\core\management\base.py", line 342, in execute
    self.check()
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\core\management\base.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\core\management\base.py", line 361, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
    for pattern in resolver.url_patterns:
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\urls\resolvers.py", line 313, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\urls\resolvers.py", line 306, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "D:/WindowsFolders/Documents/Python/ReaderProject\ReaderProject\urls.py", line 25, in <module>
    from Reader import views
  File "D:/WindowsFolders/Documents/Python/ReaderProject\Reader\views.py", line 7, in <module>
    from .forms import UploadForm
  File "D:/WindowsFolders/Documents/Python/ReaderProject\Reader\forms.py", line 12, in <module>
    class UploadForm(forms.Form):
  File "D:/WindowsFolders/Documents/Python/ReaderProject\Reader\forms.py", line 15, in UploadForm
    for manga in mangas:
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\models\query.py", line 256, in __iter__
    self._fetch_all()
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\models\query.py", line 1087, in _fetch_all
    self._result_cache = list(self.iterator())
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\models\query.py", line 54, in __iter__
    results = compiler.execute_sql()
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\models\sql\compiler.py", line 835, in execute_sql
    cursor.execute(sql, params)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\backends\utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\utils\six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:\Users\Andreas\ReaderProject\lib\site-packages\django\db\backends\sqlite3\base.py", line 337, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: Reader_manga

告诉我你需要知道什么才能提供帮助,我会添加它。

5 个答案:

答案 0 :(得分:1)

因此解决此问题的最快方法是将所有内容复制到一个新项目中(可能只是删除所选部分并重新添加)

然后再次制作应用程序,复制设置和模型。然后window.location.search然后window.location.pathname。然后我可以简单地复制视图,网址和其他所有内容。

出了什么问题?也许迁移发生了一些事情,从头开始进行迁移有助于解决问题。

答案 1 :(得分:1)

我的修复是运行

python manage.py makemigrations app_name

而不是

python manage.py makemigrations

请参阅此相关答案:https://stackoverflow.com/a/25843194/2893090

答案 2 :(得分:0)

运行&#39; manage.py makemigrations&#39;进行新的迁移,然后重新运行“manage.py migrate&#39;应用它们。

这是我尝试迁移时给出的提示。我做了以上的事情,它对我有用。

答案 3 :(得分:0)

解决方案1 ​​
如果您没有一些关键数据和

,则可以删除“ db.sqlite”
  • 并运行<resources> <dimen name="activity_horizontal_margin">24dp</dimen> <dimen name="activity_vertical_margin">24dp</dimen> <dimen name="main_nav_icon_padding">6dp</dimen> <dimen name="main_search_height">54dp</dimen> <dimen name="main_search_marginTop">72dp</dimen> <dimen name="main_search_elevation">24dp</dimen> <dimen name="main_search_padding">16dp</dimen> <dimen name="main_search_textSize">20sp</dimen> </resources>

对我有用。看来python manage.py migration看不到您是否通过python manage.py migration从数据库中删除了表。感谢Petar Luketina在上方提供提示

解决方案2
在sqlite3或您的数据库中有一个表drop table "your table name",用于保存迁移记录。如果您从数据库中手动删除了该表。然后,您还应该使用

从数据库中删除它
  • django_migration


否则,将不会应用迁移found in this StackOverflow thread

答案 4 :(得分:0)

迁移也是如此 根据您的操作系统打开您的终端/命令行/ git bash并运行以下

  1. python manage.py makemigrations
  2. python manage.py migration