相关疑难解决方法(0)

重命名Users表中的列时,获取:SQLite3 :: ConstraintException:FOREIGN KEY约束失败:DROP TABLE“ users”

我正在使用Sqlite开发Rails应用程序,并且有一个与其他几个表关联的用户表。尝试在Users中重命名列时,运行rails db:migrate时出现主题错误。

我在这里看到很多类似问题的帖子,但没有一个奏效。具体来说,常见的补救方法似乎是在所有has_many和has_one关联上使用“ dependent::destroy”。我正在这样做,但是仍然出现错误。

我究竟做错了什么?

下面是我的代码:

class User < ApplicationRecord
  devise :database_authenticatable, :registerable,
  :recoverable, :rememberable, :trackable, :validatable

  has_one :profile, dependent: :destroy
  has_many :bikes, dependent: :destroy
  has_many :bookings, dependent: :destroy
  has_many :rented_bikes, through: :bookings, source: :bike
  has_many :conversations, dependent: :destroy
  has_many :likes, dependent: :destroy
  has_many :liked_bikes, through: :likes, :source => :bike
  has_many :viewed_bikes, through: :views, :source => :bike
  has_many :views, dependent: :destroy
  has_many :reviews, dependent: :destroy
end

class Profile < ApplicationRecord
  belongs_to :user
end

class Bike < ApplicationRecord
  belongs_to :user
  has_many …
Run Code Online (Sandbox Code Playgroud)

sqlite ruby-on-rails foreign-keys

1
推荐指数
1
解决办法
283
查看次数

标签 统计

foreign-keys ×1

ruby-on-rails ×1

sqlite ×1