gpt4 book ai didi

ruby-on-rails - Rails : Getting “Table events has no column named user_id” error on all tests

转载 作者:行者123 更新时间:2023-12-03 16:10:34 25 4
gpt4 key购买 nike

我所有的测试都给出了错误。我试图整理了好一阵子,但无济于事。它们类似于以下内容:

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属性,并且它们可以运行。

至于测试,我环顾四周,发现提到了 Check your fixtures file! Whenever I'd rename columns, I'd usually forget to tweak my fixtures to match. This causes an error on every single test, just like you're seeing. Error in all unit and functional tests after altering column names of a table虽然不确定这是否适用于我的问题。如您所见,它说事件已经有一个user_id。我不太了解所有测试如何失败,甚至看似无关的测试也是如此。那就是让我失望的原因。

我在GitHub的这一部分: https://github.com/attatae/and_silva

还看着这个: Rails 3.0.7 with ruby 1.9.2 fixtures with :belongs_to and :has_many gives "table users has no column named posts"

我需要在xxyynum_create_events.rb中插入user_id吗? ie integer :user_id下的 create table :events do |t|
我尝试过的其他方法:
耙db:test:prepare
耙db:migrate RAILS_ENV = test
删除然后重新创建数据库

所有帮助非常感谢。

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

发布后,我将[bignum] _create_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

然后,我尝试执行 bundle exec rake db:reset && bundle exec rake db:populate && bundle exec rake db:test:prepare,但收到错误消息““不知道如何构建任务'db:populate'。

所以我改为尝试 bundle exec rake db:drop && bundle exec rake db:create && bundle exec rake db:migrate && bundle exec db:test:prepare,但它说 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'`

接下来,我进入开发和测试沙箱,他们都说 Event(Table doesn't exist)

然后,我尝试运行rails只是为了确保我什至试图修复正确的程序,因为我的应用程序之前运行得很好,显然在事件中没有user_id方面。

该网站说 Migrations are pending; run 'rake db:migrate RAILS_ENV=development' to resolve this issue.我尝试运行rake db:migrate代替。然后它说:
==  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

然后我跑了耙,得到了与以前相同的准确错误,共进行了32次测试。

我运行了rake db:migrate RAILS_ENV = development,然后出现了相同的AQLite3 ALTER TABLE错误。

最佳答案

检查固定装置,查看它们是否与您的架构不匹配。

我有一个类似的问题。即使我从数据库中删除了我的装置,它仍然具有旧的值(value)。因此,Rails测试正在加载固定装置,它们与我更新的数据库不同。

关于ruby-on-rails - Rails : Getting “Table events has no column named user_id” error on all tests,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22801377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com