下面的迁移会抛出下面的错误。我做错了什么?
class CreateJoinTableProjectsUsers < ActiveRecord::Migration[7.0]
def change
create_join_table :projects, :users do |t|
# t.index [:project_id, :user_id]
# t.index [:user_id, :project_id]
t.references :creator, references: :users, null: false, foreign_key: true
t.timestamps
end
end
end
字符串
错误:
== 20230720163543 CreateJoinTableProjectsUsers: migrating =====================
-- create_join_table(:projects, :users)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "creators" does not exist
/.../db/migrate/20230720163543_create_join_table_projects_users.rb:3:in `change'
Caused by:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "creators" does not exist
/.../db/migrate/20230720163543_create_join_table_projects_users.rb:3:in `change'
Caused by:
PG::UndefinedTable: ERROR: relation "creators" does not exist
/.../db/migrate/20230720163543_create_join_table_projects_users.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
型
它说关系creators
不存在,但我试图创建它,所以它确实不存在。
1条答案
按热度按时间b4lqfgs41#
我已经解决了这个问题,我传递了错误的参数。下面是实现的方法:
字符串