Python论坛  - 讨论区

标题:[python-chinese] django数据库的自动增加前缀

2006年04月03日 星期一 16:37

风向标 vaneoooo at gmail.com
Mon Apr 3 16:37:53 HKT 2006

设计有一个models:


#coding utf-8
from django.db import models

# Create your models here.
class User(models.Model):
       username = models.CharField('用户名', maxlength=30, unique=True)
       email = models.EmailField('Email', blank=True)
       password = models.CharField('密码', maxlength=128)
       def __repr__(self):
              return self.username

初始化syncdb后,进入manage.py shell

运行:

>>> from test.login.models import User

>>> name=User(username='wanglao3',email='lao3 at sina.com',password='555')
>>> name
wanglao3

>>> name.save()

Traceback (most recent call last):
  File "", line 1, in ?
  File "d:\python24\lib\site-packages\django-
0.91-py2.4.egg\django\db\models\bas
e.py", line 191, in save
    ','.join(placeholders)), db_values)
  File "d:\python24\lib\site-packages\django-
0.91-py2.4.egg\django\db\backends\u
til.py", line 12, in execute
    return self.cursor.execute(sql, params)
  File "d:\python24\lib\site-packages\django-
0.91-py2.4.egg\django\db\backends\m
ysql\base.py", line 31, in execute
    return self.cursor.execute(sql, params)
  File "D:\Python24\lib\site-packages\MySQLdb\cursors.py", line 137, in
execute
    self.errorhandler(self, exc, value)
  File "D:\Python24\lib\site-packages\MySQLdb\connections.py", line 33, in
defau
lterrorhandler
    raise errorclass, errorvalue
OperationalError: (1054, "Unknown column 'username' in 'field list'")

我琢磨着我初始化了数据库,怎么会在字段列表中没有这个项目呢

mysql下查了一下数据库结构,结果是:

+-----------------+--------------+------+-----+---------+----------------+
| Field           | Type         | Null | Key | Default | Extra          |
+-----------------+--------------+------+-----+---------+----------------+
| id              | int(11)      |      | PRI | NULL    | auto_increment |
| test_username | varchar(30)  |      | UNI |         |                |
| test_email    | varchar(75)  |      |     |         |                |
| test_password | varchar(128) |      |     |         |                |
+-----------------+--------------+------+-----+---------+----------------+

它会自动加前缀噢?那以前limodou兄的wiki讲解部分也能通过?

是新版本的东西?有点疑惑了
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060403/e4e7f49a/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号