Django无法使用“python manage.py syncdb”命令创建默认表

时间:2012-05-21 10:34:18

标签: python django

我是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​​,&#39; alpha&#39;,1) 操作系统:Windows XP

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

5 个答案:

答案 0 :(得分:5)

阅读您的错误消息:

  

NotperlyConfigured:您尚未设置数据库ENGINE设置   爱好。

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

答案 1 :(得分:1)

You haven't set the database ENGINE setting yet.

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

答案 2 :(得分:1)

你需要在settings.py

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

答案 3 :(得分:1)

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

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

版本1.9

中将完全删除

syncdb

尝试使用 makemigrations 迁移

python manage.py makemigrations app1 app2 app3

将在每个应用迁移文件夹中创建迁移脚本

python manage.py migrate

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

答案 4 :(得分:0)

安装MySQL-python为我工作!