manmanage.py syncdb的syncdb和sqlall什么区别

11520人阅读
Django(11)
Python(9)
django-admin.py&startproject&mysite&该命令在当前目录创建一个 mysite 目录。django-admin.py这个文件在C:\Python27\Lib\site-packages\django\bin文件夹里,可以把该目录添加到系统Path里面。Django内置一个轻量级的Web服务器。进入 mysite 目录的话,现在进入其中,并运行&python&manage.py&runserver&命令启动服务器,用http://127.0.0.1:8000/可以进行浏览了,8000是默认的端口号。python manage.py runserver 8080更改服务器端口号python&manage.py&shell启动交互界面python manage.py startapp books创建一个app,名为bookspython manage.py validate验证Django数据模型代码是否有错误python manage.py sqlall books为模型产生sql代码python manage.py syncdb运行sql语句,创建模型相应的Tablepython&manage.py&dbshell启动数据库的命令行工具manage.py&sqlall books查看books这个app下所有的表python manage.py syncdb同步数据库,生成管理界面使用的额外的数据库表
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2220695次
积分:16193
积分:16193
排名:第404名
原创:134篇
转载:56篇
评论:788条1.django-admin.py startproject mysite
开始一个项目,会初始化一些项目的结构文件
2.python manage.py runserver ip:port
如: python manage.py runserver 127.0.0.1:8080
利用ip可以访问不在同一个主机的数据库
3.python manage.py syncdb
注:会创建在setting.py下配置的INSTALL_APPS下的所有
app,创建其对应的数据表到指定的数据库,但只创建
不存在的表
4.python manage.py startapp polls
开启一个app叫polls,创建如下文件:
__init__.py
5.python manage.py sql polls
将创建polls的模块的sql语句打印出来,但这不数据库中创建
对应的表,若要创建对应的表,需要先在INSTALL_APPS中配置
指定的app,然后运行同步数据库命令:python manage.py syncdb
6.python manage.py validate
检测模块中是否有错误
7.python manage.py sqlclear polls
打印出清楚模块polls的数据表的方法
8.python manage.py sqlindexes polls
打印出在模块polls中创建的索引
9.python manage.py sqlall polls
打印出所有的创建模块polls的sql语句,包括索引
10.需要在模块中写__unicode__()方法而不是__str__()方法
因为__str__()方法调用__unicode__()方法,并且__str__()
方法返回一个utf-8字符串,然而__unicode__()方法返回unicode
字符串,因为所有的从数据库中查出的数据都转换为unicode码,这
样,__unicode__()类似与unicode(p),转换为unicode码,__str__()
类似于encode('utf-8'),转换为utf-8
11.创建超级用户
manage.py createsuper --username=joe --email=
12.设置Django时区
修改TIME_ZONE='Asia/Shanghai',然后重启就ok了
13.查找已安装的模块的路径
python -c "
import sys
sys.path = sys.path[1:]
import django
print(django.__path__)"
阅读(...) 评论()帐号:密码:下次自动登录{url:/nForum/slist.json?uid=guest&root=list-section}{url:/nForum/nlist.json?uid=guest&root=list-section}
贴数:6&分页:请输入新的昵称发信人: xxxss (请输入新的昵称), 信区: Python
标&&题: Re: [问题]激活Django admin,输python manage.py syncdb,报了
发信站: 水木社区 (Sun May&&6 10:04:36 2012), 转信 && 人家不是说了么,sql语句语法错误
【 在 lzrak47 (byrbyr) 的大作中提到: 】
: 报错django.db.utils.DatabaseError: (1064, "You have an error in your SQL check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")
: 有大神解答一下吗~谢谢啦~
I love cats...they taste just like chicken
If at first you don't succeed,&&&&&&&&&& destroy all evidence that you tried.&& A conclusion is the place where you got tired of thinking.&& Experience is something you don't get until just after you need it.&& For every action, there is an equal and opposite criticism.
Never do card tricks for the group you play poker with.&&&&&& ※ 来源:·水木社区 newsmth.net·[FROM: 60.247.46.*]
byrbyr发信人: lzrak47 (byrbyr), 信区: Python
标&&题: Re: [问题]激活Django admin,输python manage.py syncdb,报了
发信站: 水木社区 (Sun May&&6 15:30:18 2012), 转信 && 我是按照教程这样严格执行的:
将'django.contrib.admin'加入setting的INSTALLED_APPS配置中 (INSTALLED_APPS中的配置顺序是没有关系的, 但是我们喜欢保持一定顺序以方便人来阅读)
保证INSTALLED_APPS中包含'django.contrib.auth','django.contrib.contenttypes'和'django.contrib.sessions',Django的管理工具需要这3个包。 (如果你跟随本文制作mysite项目的话,那么请注意我们在第五章的时候把这三项INSTALLED_APPS条目注释了。现在,请把注释取消。)1
确保MIDDLEWARE_CLASSES 包含'monMiddleware' 、'django.contrib.sessions.middleware.SessionMiddleware' 和'django.contrib.auth.middleware.AuthenticationMiddleware' 。(再次提醒,如果有跟着做mysite的话,请把在第五章做的注释取消。)2
运行 python manage.py syncdb ,报错了。 && 【 在 xxxss 的大作中提到: 】
: 人家不是说了么,sql语句语法错误
:&& && -- && ※ 来源:·水木社区 ·[FROM: 59.64.255.*]
老鱼发信人: hgoldfish (老鱼), 信区: Python
标&&题: Re: [问题]激活Django admin,输python manage.py syncdb,报了
发信站: 水木社区 (Sun May&&6 16:26:12 2012), 转信 && 贴settings.py里面的sql配置。 && 【 在 lzrak47 (byrbyr) 的大作中提到: 】
: 我是按照教程这样严格执行的:
: 将'django.contrib.admin'加入setting的INSTALLED_APPS配置中 (INSTALLED_APPS中的配置顺序是没有关系的, 但是我们喜欢保持一定顺序以方便人来阅读)
: 保证INSTALLED_APPS中包含'django.contrib.auth','django.contrib.contenttypes'和'django.contrib.sessions',Django的管理工具需要这3个包。 (如果你跟随本文制作mysite项目的话,那么请注意我们在第五章的时候把这三项INSTALLED_APPS条目注释了。现在,请把注释取消
: ...................
灭绝人性啊 &&&& ※ 来源:·水木社区 newsmth.net·[FROM: 125.78.148.*]
byrbyr发信人: lzrak47 (byrbyr), 信区: Python
标&&题: Re: [问题]激活Django admin,输python manage.py syncdb,报了
发信站: 水木社区 (Sun May&&6 21:55:42 2012), 转信 &&&& DATABASES = { &&&& 'default': { &&&&&&&& 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. &&&&&&&& 'NAME': 'learn',&&&&&&&&&&&&&&&&&&&&&&# Or path to database file if using sqlite3. &&&&&&&& 'USER': 'root',&&&&&&&&&&&&&&&&&&&&&&# Not used with sqlite3. &&&&&&&& 'PASSWORD': '6507828',&&&&&&&&&&&&&&&&&&# Not used with sqlite3. &&&&&&&& 'HOST': 'localhost',&&&&&&&&&&&&&&&&&&&&&&# Set to empty string for localhost. Not used with sqlite3. &&&&&&&& 'PORT': '3306', &&&&&&&& 'charset':'utf-8',&&&&&&&&&&&&&&&& # Set to empty string for default. Not used with sqlite3. &&&& }
} && 又查了一下,发现是进展到createsuperuser才报SQL错误。。
【 在 hgoldfish 的大作中提到: 】
: 贴settings.py里面的sql配置。
:&& && -- && ※ 来源:·水木社区 ·[FROM: 59.64.255.*]
请输入新的昵称发信人: xxxss (请输入新的昵称), 信区: Python
标&&题: Re: [问题]激活Django admin,输python manage.py syncdb,报了
发信站: 水木社区 (Sun May&&6 23:34:32 2012), 转信 && manage.py sqlall或者validate什么的执行一下看看,然后试试哪句出错了,
【 在 lzrak47 (byrbyr) 的大作中提到: 】
: DATABASES = {
:&&&& 'default': {
:&&&&&&&& 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
: ...................
I love cats...they taste just like chicken
If at first you don't succeed,&&&&&&&&&& destroy all evidence that you tried.&& A conclusion is the place where you got tired of thinking.&& Experience is something you don't get until just after you need it.&& For every action, there is an equal and opposite criticism.
Never do card tricks for the group you play poker with.&&&&&& ※ 来源:·水木社区 newsmth.net·[FROM: 125.33.179.*]
byrbyr发信人: lzrak47 (byrbyr), 信区: Python
标&&题: Re: [问题]激活Django admin,输python manage.py syncdb,报了
发信站: 水木社区 (Mon May&&7 11:16:38 2012), 转信 &&&& 这俩都没问题。
但是createsuperuser出错。。
我的版本Django 1.2&& mysql 5.0 python2.6
【 在 xxxss 的大作中提到: 】
: manage.py sqlall或者validate什么的执行一下看看,然后试试哪句出错了,
&& -- && ※ 来源:·水木社区 ·[FROM: 1.202.198.*]
文章数:6&分页:
抽奖到手软!将狂欢进行到底!python(70)
原文:http://blog.csdn.net/qq/article/details/9530567
命令执行、错误修复常用命令
manage.py syncdb。本命令会修复SQL的匹配问题,同步数据库,生成管理界面使用的额外的数据库表。例如:
2,manage.py
sqlall book &。查看book这个app下所有的SQL表。例如:
3,python manage.py dbshell .本命令会显示数据库版本信息(粗蓝色字体)、数据条目(红色字体)。并在命令下启动数据库的命令行工具.
django 管理界面的建立和命令排序
1.创建Project为testadmin
django-admin.py startproject testadmin
文档结构如下:
D:\DJCODE\TESTADMIN
\---testadmin
settings.py
__init__.py
2.配置数据库(在postgreSQL中用pgAdmin新建了一个数据库django)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'django',
# Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'postgres',
'PASSWORD': '911027',
'HOST': '',
# Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '',
# Set to empty string for default.
3.创建一个应用为book
python manage.py startapp book
在book文件夹中找到models.py文件,将其代码修改为第六、七章中的代码即可,文件中代码如下:
from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
然后配置app,将其添加到settings.py文件相应的地方,如:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'book',#添加这一项,和前面那章不同,前面的是books,注意别搞错了
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
最后验证模型并且执行代码。
D:\Djcode\testadmin&python manage.py validate
0 errors found
D:\Djcode\testadmin&python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table book_publisher
Creating table book_author
You just installed Django's auth system, which means you don't have any superuse
rs defined.
Would you like to create one now? (yes/no):
然后再按照下图操作即可。
创建后的auth的用户名为:django 密码为:911027
说明:为什么直接跳到Auth的创建过程了呢?因为在settings.py中INSTALLED_APP里面并没有注释掉:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
只要在其前面加上#号即可。
4.配置admin和url
将settings.py中的INSTALLED_APP中的admin选项前面的#好去掉。
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
更改urls.py文件代码如下:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin#将注释取消
admin.autodiscover()#将注释取消
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'testadmin.views.home', name='home'),
# url(r'^testadmin/', include('testadmin.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),#将注释取消
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),#将注释取消
输入:&访问后看到如下界面。
输入用户名django和密码911027即可登陆。
&当然如果你的母语不是英语,而你不想用它来配置你的浏览器,你可以做一个快速更改来观察Django管理工具是否被翻译成你想要的语言。 仅需添加django.middleware.locale.LocaleMiddleware 到settings.py文件中MIDDLEWARE_CLASSES设置中,并确保它在django.contrib.sessions.middleware.SessionMiddleware之后。
5.将Models添加到Admin管理界面中
在上一步进入到Admin管理界面后,你只能看到几项简单的操作,其实我们最重要的是对book这个app进行操作,比如添加相关的信息等,那么我们就需要将其注册到Admin管理界面中来。具体如下:
在book目录下创建admin.py文件,其代码如下:
from django.contrib import admin
from book.models import Publisher, Author #这里需要特别注意,此处是book而不要因为看到别的书写成mysite.book
admin.site.register(Publisher)
admin.site.register(Author)
完成后重启web服务,在登陆:&界面,你会注意到多了点什么呢?如下图:
django 的使用注意:
1,数据库名称与Key有对应关系,与APP有对应关系。
2,每次“ &django-admin.py startproject &***** ”中创建的KEY不同。
&&&&& 所以用不同的project不能用来登录不同的DB(数据库)。
&&&&& 提示:OperationalError: (1045, &Access denied for user 帐号名称'@'localhost' (using password: YES)&)
3, 如果不同的project需要登录以前的project的DB,需要先python manage.py changepassword &××× 。
& &或者使用命令行工具python
manage.py syncdb &进行同步【(可能的情况下)。但——通常是路径和设置问题)】。
4,网上的文章大多抄袭,请不要相信,最好相信自己摸索,一步一步,步步为营。
5,books管理者(admin)文件夹应处于和settings.py同一级别根目录下。
manage.py通常使用的命令
python manage.py changepassword &××× (改变密码××代表已经有的账户)
python manage.py createsuperuser &××× &(创造账户××代表已经想创造的新账户)
python manage.py & &base
python manage.py & &cleanup
python manage.py & &compilemessages
python manage.py & & createcachetable
python manage.py & & dbshell
python manage.py & & diffsettings
python manage.py & &dumpdata
python manage.py & & flush
python manage.py & &inspectdb
python manage.py & & loaddata
python manage.py & & makemessages
python manage.py & & runfcgi
python manage.py & & shell
python manage.py & &sql
python manage.py & &sqlall
python manage.py & &sqlclear
python manage.py & &sqlcustom
python manage.py & & sqlflush
python manage.py & & sqlindexes
python manage.py & & sqlinitialdata
python manage.py & & sqlsequencereset
python manage.py & & startapp
python manage.py & & startproject
python manage.py & & syncdb
python manage.py & &test &&(测试中将建造默认:Creating test database for alias 'default'.................................................需要1分钟左右,需要看计算机配置情况)
python manage.py & & testserver
python manage.py & & validate &(可以验证安装错误,安装正确则显示:0 errors found)
python &makelocalealias.py
python &msgfmt.py
python &pygettext.py
[sessions]
python manage.py & & clearsessions
[staticfiles]
&python manage.py & &collectstatic
python manage.py & & findstatic
python manage.py&&&& runserver&& 运行
django 安装完成后,在数据库安装好后,请进行测试,python manage.py&& &test&& 如下显示错误数据,方便调试:
FAIL: test_clearsessions_command (django.contrib.sessions.tests.FileSessionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
& File &X:\python27\django\test\utils.py&, line 220, in inner
&&& return test_func(*args, **kwargs)
& File &X:\python27\django\contrib\sessions\tests.py&, line 444, in test_clearsessions_command
&&& self.assertEqual(1, count_sessions())
AssertionError: 1 != 2
----------------------------------------------------------------------
Ran 478 tests in 78.472s
FAILED (failures=1, skipped=2, expected failures=1)
Destroying test database for alias 'default'...
X:\website\mysite&
Django开发中常用的命令总结
1. 创建一个Django Project#使用下面的命令可以创建一个projectdjango-admin.py startproject mysite #创建好之后可以看到如下的pro...
1. 创建一个Django Project
django-admin.py
startproject mysite
&&manage.py
&&&&&&__init__.py
&&&&&&settings.py
&&&&&&urls.py
&&&&&&wsgi.py
2. 启动刚刚创建的Project
进入mysite目录,并运行python manage.py runserver命令。默认情况下runserver的启动端口是8000,如果需要更改端口号,可以将其以参数的形式传进去
manage.py runserver 8080
3. 启动交互式的命令模式
通常需要测试一些简单的Django代码,这时就可以使用这种交互式的shell来完成
manage.py shell
4. 创建Django App
manage.py startapp books
&&__init__.py
&&models.py
&&tests.py
&&views.py
5. 校验Model的有效性
通常为了连接数据库,我们需要创建与数据库表相对应的Model,当Model创建好之后可以使用下面的命令来校验Model的有效性
manage.py validate
如果看到了如下的输出信息,表示你的Model没有问题
0 errors found
6. 生成SQL schema
确认Model没有问题时候,Django为我们提供了一个工具帮助生成创建数据库的schema
manage.py sqlall books
这个命令可以将创建Table的shema输出到命令行,但是不能将其同步创建到数据库,为了将其同步到数据库中,Django也为我们考虑到了
7. 同步Model到数据库
manage.py syncdb
manage.py dbshell
django命令解释
Django是一个python用于快速开发web应用的框架,它的很多特性使用极其方便快捷。当创建一个django项目和对项目进行管理的时候,会涉及到很多命令行命令。本文对其进行一些总结,以供方便查询。
django-admin.py startproject mysite
该命令在当前目录创建一个 mysite 目录。
django-admin.py这个文件在C:\Python27\Lib\site-packages\django\bin文件夹里,可以把该目录添加到系统Path里面。
Django内置一个轻量级的Web服务器。
进入 mysite 目录的话,现在进入其中,并运行&python manage.py runserver&命令
启动服务器,用http://127.0.0.1:8000/可以进行浏览了,8000是默认的端口号。
python manage.py runserver 8080
更改服务器端口号
python manage.py shell
启动交互界面
python manage.py startapp books
创建一个app,名为books
python manage.py validate
验证Django数据模型代码是否有错误
python manage.py sqlall books
为模型产生sql代码
python manage.py syncdb
运行sql语句,创建模型相应的Table
python manage.py dbshell
启动数据库的命令行工具
manage.py sqlall books
查看books这个app下所有的表
python manage.py syncdb
同步数据库,生成管理界面使用的额外的数据库表
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:176322次
积分:2711
积分:2711
排名:第9213名
原创:43篇
转载:367篇
(11)(6)(7)(8)(4)(2)(7)(4)(6)(2)(13)(46)(10)(11)(14)(10)(30)(28)(7)(17)(23)(13)(27)(52)(13)(7)(8)(1)(1)(4)(1)(4)(1)(1)(1)(3)(7)(1)This covers Django version 0.95 and the development version. Old docs:&,&
django-admin.py&is Django's command-line utility for administrative tasks. This document outlines all it can do.
django-admin.py是Django的命令行管理系统,这篇文档将详细介绍他的功能。
In addition,&manage.py&is automatically created in each Django project.&manage.py&is a thin wrapper around&django-admin.py&that takes care of two things for you before delegating to&django-admin.py:实际上,文件manage.py会在每个Django工程创立的时候自动建立,manage.py是django-admin.py功能的一个简单封装,它会为django-admin.py启用之前做好两项工作:
It puts your project's package on&sys.path.
将工程包文件放入sys.path路径
It sets the&DJANGO_SETTINGS_MODULE&environment variable so that it points to your project's&settings.py&file.
设置DJANGO_SETTINGS_MODULE变量指向你创立工程中的settings.py文件。
The&django-admin.py&script should be on your system path if you installed Django via its&setup.py&utility. If it's not on your path, you can find it insite-packages/django/bin&within your Python installation. Consider symlinking to it from some place on your path, such as&/usr/local/bin.如果你通过setup.py方式安装Django,django-admin.py脚本会被加入到系统路径。如果不在系统路径,你可以在Python安装路径下的site-packages/django/bin目录下找到,并将他加入到你的系统路径下。
Generally, when working on a single Django project, it's easier to use&manage.py. Use&django-admin.py&with&DJANGO_SETTINGS_MODULE, or the&--settingscommand line option, if you need to switch between multiple Django settings files.一般情况下,对单个Django project,使用manage.py没有什么问题,如果你需要在不同的Django project间使用django-admin.py,那么需要使用DJANGO_SETTINGS_MODULE或--settings命令行参数。
django-admin.py&action&[options]
manage.py&action&[options]
action&should be one of the actions listed in this document.&options, which is optional, should be zero or more of the options listed in this document.
Run&django-admin.py&--help&to display a help message that includes a terse list of all available actions and options.
Most actions take a list of&appname``s.&An&``appname&is the basename of the package containing your models. For example, if your&INSTALLED_APPScontains the string&'mysite.blog', the&appname&is&blog.
Available actions
adminindex [appname appname ...]
Prints the admin-index template snippet for the given appnames.
Use admin-index template snippets if you want to customize the look and feel of your admin's index page. See&&for more information.
createcachetable [tablename]
Creates a cache table named&tablename&for use with the database cache backend. See the&&for more information.
Runs the command-line client for the database engine specified in your&DATABASE_ENGINE&setting, with the connection parameters specified in yourDATABASE_USER,&DATABASE_PASSWORD, etc., settings.
For PostgreSQL, this runs the&psql&command-line client.
For MySQL, this runs the&mysql&command-line client.
For SQLite, this runs the&sqlite3&command-line client.
This command assumes the programs are on your&PATH&so that a simple call to the program name (psql,&mysql,&sqlite3) will find the program in the right place. There's no way to specify the location of the program manually.
diffsettings
Displays differences between the current settings file and Django's default settings.比较当前settings文件和Django缺省settings文件之间的差异。
Settings that don't appear in the defaults are followed by&"###". For example, the default settings don't define&ROOT_URLCONF, so&ROOT_URLCONF&is followed by&"###"&in the output of&diffsettings.在缺省settings中不存在的以"###"标识。
Note that Django's default settings live in&django/conf/global_settings.py, if you're ever curious to see the full list of defaults.
Introspects the database tables in the database pointed-to by the&DATABASE_NAME&setting and outputs a Django model module (a&models.py&file) to standard output.
Use this if you have a legacy database with which you'd like to use Django. The script will inspect the database and create a model for each table within it.
As you might expect, the created models will have an attribute for every field in the table. Note that&inspectdb&has a few special cases in its field-name output:
If&inspectdb&cannot map a column's type to a model field type, it'll use&TextField&and will insert the Python comment&'This&field&type&isa&guess.'&next to the field in the generated model.
If the database column name is a Python reserved word (such as&'pass',&'class'&or&'for'),&inspectdb&will append&'_field'&to the attribute name. For example, if a table has a column&'for', the generated model will have a field&'for_field', with the&db_column&attribute set to&'for'.inspectdb&will insert the Python comment&'Field&renamed&because&it&was&a&Python&reserved&word.'&next to the field.
This feature is meant as a shortcut, not as definitive model generation. After you run it, you'll want to look over the generated models yourself to make customizations. In particular, you'll need to rearrange models' order, so that models that refer to other models are ordered properly.
Primary keys are automatically introspected for PostgreSQL, MySQL and SQLite, in which case Django puts in the&primary_key=True&where needed.
inspectdb&works with PostgreSQL, MySQL and SQLite. Foreign-key detection only works in PostgreSQL and with certain types of MySQL tables.
install [appname appname ...]
Executes the equivalent of&sqlall&for the given appnames.
runserver [optional port number, or ipaddr:port]
Starts a lightweight development Web server on the local machine. By default, the server runs on port 8000 on the IP address 127.0.0.1. You can pass in an IP address and port number explicitly.
If you run this script as a user with normal privileges (recommended), you might not have access to start a port on a low port number. Low port numbers are reserved for the superuser (root).
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that's how it's gonna stay. We're in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
The development server automatically reloads Python code for each request, as needed. You don't need to restart the server for code changes to take effect.
When you start the server, and each time you change Python code while the server is running, the server will validate all of your installed models. (See the&validate&command below.) If the validator finds errors, it will print them to standard output, but it won't stop the server.
You can run as many servers as you want, as long as they're on separate ports. Just execute&django-admin.py&runserver&more than once.
Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g.&192.168.2.1) or&0.0.0.0.
Port 7000 on IP address 127.0.0.1:
django-admin.py runserver 7000
Port 7000 on IP address 1.2.3.4:
django-admin.py runserver 1.2.3.4:7000
Serving static files with the development server
By default, the development server doesn't serve any static files for your site (such as CSS files, images, things under&MEDIA_ROOT_URL&and so forth). If you want to configure Django to serve static media, read the&&documentation.
Turning off auto-reload
To disable auto-reloading of code while the development server is running, use the&--noreload&option, like so:如果要在服务已启动后禁止自动加载代码功能,可使用--noreload参数。
django-admin.py runserver --noreload
Starts the Python interactive interpreter.
Django will use&, if it's installed.&If you have IPython installed and want to force use of the "plain" Python interpreter, use the&--plainoption, like so:
django-admin.py shell --plain
sql [appname appname ...]
Prints the CREATE TABLE SQL statements for the given appnames.
sqlall [appname appname ...]
Prints the CREATE TABLE and initial-data SQL statements for the given appnames.
Refer to the description of&sqlinitialdata&for an explanation of how to specify initial data.
sqlclear [appname appname ...]
Prints the DROP TABLE SQL statements for the given appnames.
sqlindexes [appname appname ...]
Prints the CREATE INDEX SQL statements for the given appnames.
sqlinitialdata [appname appname ...]
Prints the initial INSERT SQL statements for the given appnames.
For each model in each specified app, this command looks for the file&&appname&/sql/&modelname&.sql, where&&appname&&is the given appname and&modelname&&is the model's name in lowercase. For example, if you have an app&news&that includes a&Story&model,&sqlinitialdata&will attempt to read a file&news/sql/story.sql&and append it to the output of this command.
Each of the SQL files, if given, is expected to contain valid SQL. The SQL files are piped directly into the database after all of the models' table-creation statements have been executed. Use this SQL hook to populate tables with any necessary initial records, SQL functions or test data.
sqlreset [appname appname ...]
Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given appnames.
sqlsequencereset [appname appname ...]
Prints the SQL statements for resetting PostgreSQL sequences for the given appnames.
See&&for more information.
startapp [appname]
Creates a Django app directory structure for the given app name in the current directory.
startproject [projectname]
Creates a Django project directory structure for the given project name in the current directory.
Creates the database tables for all apps in&INSTALLED_APPS&whose tables have not already been created.
Use this command when you've added new applications to your project and want to install them in the database. This includes any apps shipped with Django that might be in&INSTALLED_APPS&by default. When you start a new project, run this command to install the default apps.
If you're installing the&django.contrib.auth&application,&syncdb&will give you the option of creating a superuser immediately.
New in Django development version
Discover and run tests for all installed models. See&&for more information.
Available options
--settings
Example usage:
django-admin.py syncdb --settings=mysite.settings
Explicitly specifies the settings module to use. The settings module should be in Python package syntax, e.g.&mysite.settings. If this isn't provided,&django-admin.py&will use the&DJANGO_SETTINGS_MODULE&environment variable.
Note that this option is unnecessary in&manage.py, because it takes care of setting&DJANGO_SETTINGS_MODULE&for you.
--pythonpath
Example usage:
django-admin.py syncdb --pythonpath='/home/djangoprojects/myproject'
Adds the given filesystem path to the Python&. If this isn't provided,&django-admin.py&will use the&PYTHONPATH&environment variable.
Note that this option is unnecessary in&manage.py, because it takes care of setting the Python path for you.
Displays a help message that includes a terse list of all available actions and options.
New in Django development version
Inform django-admin that the user should NOT be prompted for any input. Useful if the django-admin script will be executed as an unattended, automated script.
--noreload
Disable the use of the auto-reloader when running the development server.
Displays the current Django version.
Example output:
0.9.1 (SVN)
--verbosity
New in Django development version
Example usage:
django-admin.py syncdb --verbosity=2
Verbosity determines the amount of notification and debug information that will be printed to the console. '0' is no output, '1' is normal output, and&2&is verbose output.verbosity决定运行、调试信息显示级别,0-什么也不输出,1-正常输出,2-详细信息输出
--adminmedia
New in Django development version
Example usage::django-admin.py manage.py --adminmedia=/tmp/new-admin-style/
Tells Django where to find the various CSS and JavaScript files for the admin interface when running the development server. Normally these files are served out of the Django source tree, but because some designers customize these files for their site, this option allows you to test against custom versions.
Extra niceties
Syntax coloring
The&django-admin.py&/&manage.py&commands that output SQL to standard output will use pretty color-coded output if your terminal supports ANSI-colored output. It won't use the color codes if you're piping the command's output to another program.
Bash completion
If you use the Bash shell, consider installing the Django bash completion script, which lives in&extras/django_bash_completion&in the Django distribution. It enables tab-completion of&django-admin.py&and&manage.py&commands, so you can, for instance...
Type&django-admin.py.
Press [TAB] to see all available options.
Type&sql, then [TAB], to see all available options whose names start with&sql.
Powered by&
阅读(...) 评论()

我要回帖

更多关于 manage.py syncdb报错 的文章

 

随机推荐