gpt4 book ai didi

ruby-on-rails - SQLite3::ConstraintException: xxxxx.created_at 不能为 NULL

转载 作者:行者123 更新时间:2023-12-04 05:23:26 25 4
gpt4 key购买 nike

我有一个创建艺术家并将其与用户关联的 resque 工作。用户 has_and_belongs_to_many :艺术家,艺术家 has_and_belongs_to_many :用户。

def self.perform(itunes_id, user_id=nil)
artist = Artist.find_by_itunes_id(itunes_id) || lookup_and_create_artist(itunes_id)
if user_id && user = User.find(user_id)
user.artists << artist
user.save!
end
end
user.artists << artist引发此异常:
ActiveRecord::StatementInvalid: SQLite3::ConstraintException: artists_users.created_at may not be NULL: INSERT INTO "artists_users" ("artist_id", "user_id")

我还看到了一个艺术家_流派的创建(艺术家和流派也有互惠的 HABTM 关系)
ActiveRecord::StatementInvalid: SQLite3::ConstraintException: artists_genres.created_at may not be NULL: INSERT INTO "artists_genres" ("artist_id", "genre_id")

最佳答案

事实证明,这在 Rails 中是有目的的,但已在许多问题中提出:

  • https://github.com/rails/rails/issues/7732
  • https://github.com/rails/rails/issues/7735
  • https://github.com/rails/rails/issues/4653
  • https://github.com/rails/rails/pull/4682

  • HABTM 关系不会自动设置时间戳,因此我可以删除它们或使用 has_many :artists, :through => :artists_genres关系

    关于ruby-on-rails - SQLite3::ConstraintException: xxxxx.created_at 不能为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13464299/

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