Ruby on rails Rails:Getting";表事件没有名为user“u id”的列;所有测试都有错误

Ruby on rails Rails:Getting";表事件没有名为user“u id”的列;所有测试都有错误,ruby-on-rails,Ruby On Rails,我所有的测试都有错误。我试着整理了好一阵子,但没有结果。它们类似于以下内容: 30) Error: UserTest#test_a_user_should_enter_a_first_name:

我所有的测试都有错误。我试着整理了好一阵子,但没有结果。它们类似于以下内容:

30) Error:                                                                                                     
UserTest#test_a_user_should_enter_a_first_name:                                                                 
ActiveRecord::StatementInvalid: SQLite3::SQLException: table events has no column named user_id: INSERT INTO "ev
ents" ("text", "event_start", "user_id", "created_at", "updated_at", "id") VALUES ('MyText', '2012-08-10', 20790
7133, '2014-04-02 03:43:47', '2014-04-02 03:43:47', 980190962)                                                  


 31) Error:                                                                                                     
UserTest#test_a_user_should_enter_a_last_name:                                                                  
ActiveRecord::StatementInvalid: SQLite3::SQLException: table events has no column named user_id: INSERT INTO "ev
ents" ("text", "event_start", "user_id", "created_at", "updated_at", "id") VALUES ('MyText', '2012-08-10', 20790
7133, '2014-04-02 03:43:47', '2014-04-02 03:43:47', 980190962)                                                  


 32) Error:                                                                                                     
UserTest#test_a_user_should_have_a_profile_name_without_spaces:                                                 
ActiveRecord::StatementInvalid: SQLite3::SQLException: table events has no column named user_id: INSERT INTO "ev
ents" ("text", "event_start", "user_id", "created_at", "updated_at", "id") VALUES ('MyText', '2012-08-10', 20790
7133, '2014-04-02 03:43:47', '2014-04-02 03:43:47', 980190962) 
我应该提到的是,这个应用程序本身运行得非常好。各种事情都取决于user_id属性,它们会运行

至于测试,我环顾四周,发现有人提到
检查你的fixtures文件!每当我重命名列时,我通常会忘记调整我的固定装置以匹配。这会在每个测试中导致错误,正如您所看到的。
不确定这是否适用于我的问题。正如你所看到的,它说事件已经有了一个用户id。我不太明白为什么所有的测试都失败了,即使是看起来不相关的测试。这就是让我不高兴的地方

GitHub的我的部分:

我们也看到了这一点:

是否需要将用户id插入xxyynum_create_events.rb?
ie integer:user_id
下的
create table:events do | t |

我尝试过的其他事情: rake数据库:测试:准备 rake db:migrate RAILS_ENV=test 删除然后重新创建数据库

非常感谢大家的帮助

更新===============

发布后,我将我的[bignum]\u create\u events.rb更改为:

class CreateEvents < ActiveRecord::Migration
  def change
    create_table :events do |t|
      t.string :title
      t.datetime :time_begin 
      t.string :location
      t.date :event_start
      t.text :text
      t.integer :user_id
      t.text :user 

      t.timestamps
    end
  end
end
然后我运行rake,得到了与之前相同的错误,用于32个测试


我运行了rake db:migrate RAILS\u ENV=development,然后得到了相同的AQLite3[…]ALTER TABLE错误。

查看您的/db/*模式和迁移文件,我在任何地方都看不到为事件表定义的用户id

我发现它位于
db/schema.rb

修复它并尝试:
bundle exec rake db:reset&&bundle exec rake db:populate&&bundle exec rake db:test:prepare


如果这还不够,您应该会收到一条错误消息,说明需要一些其他的
rake
任务。

检查夹具,看看它们是否与您的模式不匹配。


我也有类似的问题。我的装置有一个旧值,即使我从数据库中删除了它。因此,Rails测试正在加载夹具,它们与我更新的db不一样。

只需键入
rake db:test:prepare
。它会起作用。

在我的情况下,我的ActiveRecord中有一个
enum
值(所以我的表中只有一个整数),然后我决定将其更改为
引用。删除列并添加相应的引用之后,我得到了测试的错误。我的错误是,我忘了在添加参考的模型中添加
属于:MODEL

对不起,我是Rails新手,不太理解这个建议。如果确实找到了,测试仍然不会运行。上面显示的错误来自我添加用户\u id以创建\u事件迁移。当我编辑我的主要问题以反映时,应用程序运行,因此除此之外,在哪里进行更改还不太清楚。你的意思是添加
t.integer:user\u id
来创建事件迁移吗?我在github repo上检查了它,在当前版本中,没有user\u id@events表。我发现它是在以前的一些网站上。检查上面的链接,查看您所做更改的差异。如果您的应用程序运行良好,并且测试不正常,可能是因为您的测试和开发数据库版本不相同。您可以手动检查其中的内容。运行rails c test--sandbox
和rails c dev--sandboxtype
Event
并进行比较。然而,我的应用程序说“不知道如何构建任务'db:populate.”还有其他选择吗?还有其他错误。显然,我的应用程序开发和测试区域没有事件表。
db:populate
用于填充数据库。使用样本数据。如果你没有它,你就不需要它。如果你愿意,我们可以移动聊天室。创建一个频道,邀请我去那里。
==  AddAddressToEvent: migrating ==============================================
-- add_column(:events, :address, :string)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: events: ALTER TABLE "events" ADD "address" varchar(255)C:/Rails Projects/Git pull/and_silva/db/migrate/20140329045140_add_address_to_event.rb:3:in *change'
C:in `migrate'
Tasks: TOP => db:migrate