python models.py syncdb不起作用 [英] python models.py syncdb does not work

查看:88
本文介绍了python models.py syncdb不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第二天,我要安装Python 2.7.2& Django 1.5并创建我的第一个应用程序,现在我无法同步models.py和更新数据库。

Second day on my journey to install Python 2.7.2 & Django 1.5 and create my first application, and now I can not sync models.py and update my database.

工具:Windows Vista,Putty SSH
位置:Bluehost(www.bluehost.com)服务器

Tools: Windows Vista, Putty SSH Location: Bluehost (www.bluehost.com) Server

这里是我已经阅读但无法解决问题的主题:
为什么会因以下原因而出错python manage.py syncdb(IndentationError:意外缩进)

Here is a topic that I already read but does not solve my problem: Why did I get error for python manage.py syncdb (IndentationError: unexpected indent)

建议与制表符和空格 indentation ),但请相信我使用的是正确的缩进,如下所示(models.py)。

The advice was about tabs and spaces (indentation) in models.py, but believe that I use the correct indentation, as you can see below (models.py).

from django.db import models

# Create your models here.

class posts(models.Model):

    author = models.CharField(max_lenght = 30)
    title = models.CharField(max_lenght = 100)
    bodytext = models.TextField()
    timestamp = models.DateTimeField()



什么我已经做完了:



我已经安装了Python 2.7.2,请检查:

What I have already done:

I have installed Python 2.7.2, check:

username@domain.com [~]# python -V
Python 2.7.2 

我已经安装了Django 1.5,请检查

I have installed Django 1.5, check

username@domain.com [~]# python
Python 2.7.2 (default, Mar 27 2013, 12:07:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django import get_version
>>> get_version()
'1.5'
>>>

我已经安装了MySQL-python-1.2.4(我不确定,如果可以正常运行):

I have installed MySQL-python-1.2.4 (in this point I am not sure, if it works correctly):

username@domain.com [~]# python
Python 2.7.2 (default, Mar 27 2013, 12:07:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

我有,并成功运行了Colde:

I had problem with django-admin.py, solved it changing the .bashrc PATH entry, and ran the colde successfully:

django-admin.py startproject mysite

然后我像这样修改 models.py (以创建一个简单的博客):

Then I modified models.py like this (to create a simple blog):

from django.db import models

# Create your models here.

class posts(models.Model):

    author = models.CharField(max_lenght = 30)
    title = models.CharField(max_lenght = 100)
    bodytext = models.TextField()
    timestamp = models.DateTimeField()

然后我创建了一个 mysql数据库 和一个 用户 ,将用户添加到数据库中,并为所有特权(在bluehost前端面板中全部完成)。

Then I have created a mysql database and a user, added user to the database and gave all the privileges (done all in bluehost frontend panel).

然后我像这样修改 settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'domain_dbname',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'domain_username',
        'PASSWORD': 'password',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}



问题



现在是时候更新数据库了,我试试这个:

Problem

Now is the time to update the database, I try this:

python models.py syncdb

这就是我得到的:

Traceback (most recent call last):
  File "models.py", line 1, in <module>
    from django.db import models
  File "/home1/domain/python/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/home1/domain/python/lib/python2.7/site-packages/django/conf/__init__.py", line 52, in __getattr__
    self._setup(name)
  File "/home1/domain/python/lib/python2.7/site-packages/django/conf/__init__.py", line 45, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.



所以我的问题是:



为什么这行行不通吗?

So my question is:

Why does this line not work?

python models.py syncdb


推荐答案

使用此:

python manage.py syncdb

这篇关于python models.py syncdb不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆