问题描述
所以在尝试将用户添加到数据库时,我得到了这个。我想,我想知道它有什么专栏?所以我要求sql ...
So I got this when trying to add a User to the database. And I thought, I wonder what columns it does have? So I asked for the sql...
DatabaseError: table OmniCloud_App_user has no column named username
>>>
root@Harold:~/OmniCloud/omnicloud# python manage.py sql OmniCloud_App
BEGIN;
CREATE TABLE "OmniCloud_App_user" (
"id" integer NOT NULL PRIMARY KEY,
"email" varchar(75) NOT NULL,
"username" varchar(25) NOT NULL,
"password" varchar(30) NOT NULL
)
;
嘿!在那里!如果事实上已经列出了列,那么为什么会发生以下两行呢?
Hey! There it is! Why would it get mad at the two following lines if it seems to, in fact, have said column?
>>> u = User(email="[email protected]", username="gmail", password="gmail")
>>> u.save()
也不是我如何定义一个User类,它说 user
没有名为username的列。为什么要小写?
Also not how I am defining a User class and it says that user
has no column called username. Why does it go lowercase?
推荐答案
- 您是否运行
$> ; python manage.py syncdb
? - 自从您首次运行syncdb以来,是否更改了模型(添加了用户名)?
Syncdb仅适用于新型号。你必须自己整理迁移,这就是南方的地方。
Syncdb only works on new models. You've got to sort out migrations yourself, and that's where South comes in.
或者,您可以自行修改数据库,或使用其他应用程序更接近于该方法,称为nashvegas。
Alternatively, you can modify the database on your own, or use another app, which is closer to that method, called nashvegas.
这是您需要的SQL的近似值。
This is an approximation of the SQL that you need.
ALTER TABLE OmniCloud_App_user ADD COLUMN "username" varchar(25) NOT NULL;
这篇关于DatabaseError:表OmniCloud_App_user没有名为username的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!