相关疑难解决方法(0)

如何重命名SQLite数据库表中的列?

我需要在SQLite数据库的某些表中重命名几列.我知道之前在stackoverflow上已经提出了类似的问题,但它一般用于SQL,并且没有提到SQLite的情况.

ALTER TABLE的SQLite文档中,我认为不可能"轻松"地做这样的事情(即单个ALTER TABLE语句).

我想知道有人知道用SQLite做这种事情的通用SQL方法.

sqlite alter-table

286
推荐指数
8
解决办法
17万
查看次数

Rails 5.2错误更改或删除表列(SQLite3 :: ConstraintException:FOREIGN KEY约束失败:DROP TABLE)

我正在尝试完成从我的Blog表中更改其中一列的默认值的相当简单的壮举.我有以下迁移:

class UpdateBlogFields < ActiveRecord::Migration[5.2]
  def change
    change_column :blogs, :freebie_type, :string, default: "None"
  end
end
Run Code Online (Sandbox Code Playgroud)

相当简单,但运行时出现以下错误rake db:migrate:

StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "blogs"
Run Code Online (Sandbox Code Playgroud)

我在尝试更改或删除列时会收到此错误,但在添加列时则不会收到此错误.

我的架构如下所示:

  create_table "blogs", force: :cascade do |t|
    t.string "title"
    t.string "teaser"
    t.text "body"
    t.string "category", default: "General"
    t.string "linked_module"
    t.boolean "published", default: false
    t.datetime "published_on"
    t.integer "user_id"
    t.integer "image_id"
    t.integer "pdf_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false …
Run Code Online (Sandbox Code Playgroud)

sql sqlite ruby-on-rails

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

标签 统计

sqlite ×2

alter-table ×1

ruby-on-rails ×1

sql ×1