django1.6之mysql配置

阅读更多
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

setting 配置修改

INSTALLED_APPS = (
# 'django.contrib.admin',
# 'django.contrib.auth',
# 'django.contrib.contenttypes',
# 'django.contrib.sessions',
# 'django.contrib.messages',
# 'django.contrib.staticfiles',
'xiaoji',
)

DATABASES = {
'default': { 
'ENGINE': 'mysql.connector.django',
'NAME':'test',
'USER':'root',
'PASSWORD':'root',
'HOST':'127.0.0.1',
'PORT':'3306',
} 
}

model类创建,在xiaoji包下创建models.py,内容如下:

from django.db import models
from django.utils.translation import ugettext_lazy as _
class product(models.Model):
name = models.CharField(_('name'),max_length=15)
createtime = models.DateTimeField(_('create_datetime'),auto_now=True)
class Meta:
verbose_name = _('product')
verbose_name_plural = _('product')
db_table = 'product'
def __unicode__(self):
return self.name

最后启动python manager.py syncdb命令 创建product表

 

 

你可能感兴趣的:(django,mysql)