【问题标题】:Django unable to create default table using "python manage.py syncdb" commandDjango 无法使用“python manage.py syncdb”命令创建默认表
【发布时间】:2012-05-27 20:37:03
【问题描述】:

我是 Django 新手。我正在按照tutorial 中的说明进行操作。 当我运行python manage.py syncdb 时,我收到以下错误:

D:\MyDev\DjnagoProject\mysite>python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 9, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 420, in execute_from_command_
line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "C:\Python27\lib\site-packages\django\db\backends\dummy\base.py", line 15, in complain
    raise ImproperlyConfigured("You haven't set the database ENGINE setting yet.")
django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet.

添加信息: Python版本:2.7.2, django 版本: (1, 4, 0, 'alpha', 1) 操作系统:Windows XP

请让我知道我在哪里犯了错误。

【问题讨论】:

  • 我不知道你在关注哪个教程,但official tutorial 明确提到首先设置数据库引擎然后运行python manage.py syncdb
  • 我也在关注你在这里提到的同一份文件。这是我根据setting.py文件中的要求修改的数据库值 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', ' mysql'、'sqlite3' 或 'oracle'。 'NAME': r'D:/MyDev/DjnagoProject/mysite/myDev.db', # 如果使用 sqlite3,则为数据库文件的路径。
  • 向我们展示与数据库部分相关的 settings.py 文件的内容。还有你正在使用哪个数据库,我建议你使用为 python >2.5 内置的 sqlite3

标签: python django


【解决方案1】:

我在settings.py文件中添加数据库配置:

现在在 Django 1.8.x 上,它完全支持迁移

syncdb 将在 1.9 版中完全删除

尝试使用 ma​​kemigrationsmigrate 代替

python manage.py makemigrations app1 app2 app3

将在每个应用迁移文件夹中制作迁移脚本

python manage.py migrate

将查看数据库 django_migrations 表和迁移文件夹并迁移更改。

【讨论】:

    【解决方案2】:

    安装 MySQL-python 对我有用!

    【讨论】:

      【解决方案3】:

      你需要在settings.py中做以下两件事

      1. 在数据库字典中添加数据库引擎和凭据。
      DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.sqllite3',
              'NAME': '/home/yourname/mydb', 
              'USER': '',   
              'PASSWORD': '',  
              'HOST': '',        
              'PORT': '',  
      }
      }
      
      1. 将您的应用添加到 installed_app 列表中
      INSTALLED_APPS = (
          'com.example.myapp',
          ....
      

      【讨论】:

      • 我仍然遇到同样的错误。数据库 = { 'default': { 'ENGINE':"sqlite3", 'NAME':r"D:/MyDev/DjnagoProject/mysite/myDev.db", 'USER':'', 'PASSWORD':'', 'HOST':'', 'PORT':'', } } INSTALLED_APPS = ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites' , 'django.contrib.messages', 'django.contrib.staticfiles', 'mysite.blog', ) 我已经在 mysite 中创建了博客应用程序。
      【解决方案4】:

      阅读您的错误信息:

      ImproperlyConfigured:您尚未设置数据库 ENGINE 设置 还没有。

      检查DATABASES in your settings.py。你至少需要ENGINEdatabase NAME

      【讨论】:

      • 要么没有加载你的设置,要么你没有设置数据库引擎设置。
      • 你能建议我该怎么做吗?因为我也尝试设置 PYTHONPOATH 但没有结果。如果您能提出一些替代方案,那就太好了..
      • @vartec:当您执行pip install django 时,这些事情不是默认发生的吗?它发生在我身上
      • 我需要在我的系统环境中设置 PythonPath 或 DJANGO_SETTINGS_MODULE 路径吗?
      【解决方案5】:
      You haven't set the database ENGINE setting yet.
      

      确保您的DB credentials in settings.py 正确。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-04-11
        • 2014-06-07
        • 1970-01-01
        • 2015-04-25
        • 1970-01-01
        • 2015-01-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多