第二天在我的旅程中安裝Python 2.7.2 & Django 1.5並創建我的第一個應用程序,現在我無法同步models.py並更新我的數據庫。python models.py syncdb不起作用
工具:Windows Vista中,膩子SSH 地點:BlueHost的(www.bluehost.com)服務器
這裏是我已經看過,但並沒有解決我的問題,一個話題: Why did I get error for python manage.py syncdb (IndentationError: unexpected indent)
的建議在models.py中使用製表符和空格(縮進),但請相信我使用了正確的縮進,如下所示(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,檢查:
[email protected] [~]# python -V
Python 2.7.2
我已經安裝的Django 1.5,檢查
[email protected] [~]# 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(在這一點上,我不知道,如果它工作正常):
[email protected] [~]# 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
>>>
我有problem with django-admin.py, solved it changing the .bashrc PATH entry,併成功運行了colde:
django-admin.py startproject mysite
然後我修改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()
然後我創建了一個mysql數據庫和一個用戶,將用戶添加到數據庫並給予所有權限(在bluehost前端面板中完成所有)。
然後我修改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.
}
}
問題
現在是更新數據庫的時候,我試試這個:
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.
所以我的問題是:
這條線爲什麼不起作用?
python models.py syncdb
哦!我明白了,謝謝。花了這麼多時間之後,我想我需要休息一下。 '[email protected] [〜/ WWW /域/ mysite的]#蟒蛇manage.py執行syncdb 創建表... 創建表auth_permission 創建表auth_group_permissions 創建表auth_group 創建表auth_user_groups 創建表auth_user_user_permissions 創建表AUTH_USER 創建表django_content_type 創建表django_session中 創建表django_site 您剛剛安裝Django的身份驗證系統,這意味着你沒有定義的任何超級用戶。 你想現在創建一個嗎? (是/否):' – Eniac
是的,我沒有足夠的信譽來upvote。我已經試圖接受答案,但我應該等待3分鐘。再次感謝。 – Eniac
@Eniac是否創建了帖子表? –