Python / Django安装没有发生

时间:2013-03-22 14:14:58

标签: python django

我新装了python 2.7和django 1.3.Django 1.3被这个命令搞砸了

yum install Django MySQL-python 

安装说它已成功完成。但之后我尝试使用命令创建数据库表

   python manage.py syncdb 

我得到以下追溯

[root@localhost DemoApp]# python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute
    self.validate()
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.7/site-packages/django/core/management/validation.py", line 102, in get_validation_errors
    connection.validation.validate_field(e, opts, f)
  File "/usr/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
    db_version = self.connection.get_server_version()
  File "/usr/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 338, in get_server_version
    self.cursor()
  File "/usr/lib/python2.7/site-packages/django/db/backends/__init__.py", line 250, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 322, in _cursor
    self.connection = Database.connect(**kwargs)
  File "/usr/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1049, "Unknown database 'DemoApp'")

任何人都可以告诉我这个问题的原因是什么,安装中的任何错误

1 个答案:

答案 0 :(得分:5)

根据Django documentation

  

如果您正在使用PostgreSQL或MySQL,请确保此时已创建数据库。在数据库的交互式提示符中使用“CREATE DATABASE database_name;”执行此操作。

     

如果您使用的是SQLite,则无需事先创建任何内容 - 数据库文件将在需要时自动创建。

因此,您需要先创建数据库,让syncdb加载数据。

要创建数据库,请运行mysql程序。这为您提供了与SQL数据库交互的命令提示符。然后你跑...

create database DemoApp;

有关执行此操作的详细信息,请参阅Connecting and Disconnecting from the ServerCreating and Selecting a Database上的MySQL教程。