数据库错误:表 OmniCloud_App_user 没有名为 username 的列

发布于 2024-12-08 12:31:03 字数 795 浏览 1 评论 0原文

所以我在尝试将用户添加到数据库时得到了这个。我想,我想知道它有哪些栏目?所以我要了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
)
;

嘿!就在那里!如果它实际上似乎已经说过了,为什么它会对下面的两行感到愤怒呢?

>>> u = User(email="[email protected]", username="gmail", password="gmail")
>>> u.save()

也不是我定义 User 类的方式,它说 user 没有名为 username 的列。为什么它变成小写?

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()

Also not how I am defining a User class and it says that user has no column called username. Why does it go lowercase?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我是有多爱你 2024-12-15 12:31:03
  • 你运行过$>吗? python 管理.py 同步数据库
  • 自从您第一次运行syncdb以来,您是否更改了模型(添加了用户名)?
  • 你用的是南方吗?如果没有,您可能应该了解一下。

Syncdb 仅适用于新型号。您必须自己解决迁移问题,这就是 South 的用武之地。

或者,您可以自己修改数据库,或者使用另一个更接近该方法的应用程序,称为 nashvegas。

这是您所需的 SQL 的近似值。

ALTER TABLE OmniCloud_App_user ADD COLUMN "username" varchar(25) NOT NULL;
  • Have you run a $> python manage.py syncdb?
  • Have you changed the model (added the username) since you first ran syncdb?
  • Are you using South? If not, you should probably learn about it.

Syncdb only works on new models. You've got to sort out migrations yourself, and that's where South comes in.

Alternatively, you can modify the database on your own, or use another app, which is closer to that method, called nashvegas.

This is an approximation of the SQL that you need.

ALTER TABLE OmniCloud_App_user ADD COLUMN "username" varchar(25) NOT NULL;
与他有关 2024-12-15 12:31:03

manage.py sql 给出了如果您现在要求 syncdb 创建该表将会的 SQL。它不会向您显示表实际有什么 - 为此,您必须进入 db shell 并要求它为您描述该表。然后,您需要直接修改它或通过 South 等迁移工具进行修改。

manage.py sql gives the SQL that the table would have if you asked syncdb to create it now. It doesn't show you what the table actually has - for that you're going to have to go into your db shell and ask it to describe the table for you. Then, you'll need to modify it, either directly there or via a migration tool like South.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文