我遇到了问题。当我使用以下约束运行迁移然后转到Sqlite数据库时,这些约束在sqlite数据库中没有效果
not_null工作得很完美但不长?
Ruby On Rails 3.2
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :user_name, :null=>false, :length => 20
t.string :password, :null=>false
t.string :email, :null=>false, :length => 30
t.timestamps
end
end
end
SQLite的
-- Describe USERS
CREATE TABLE users (
"id" INTEGER NOT NULL,
"user_name" VARCHAR(255) NOT NULL,
"password" VARCHAR(255) NOT NULL,
"email" VARCHAR(255) NOT NULL,
"created_at" DATETIME NOT NULL,
"updated_at" DATETIME NOT NULL
)
答案 0 :(得分:0)
这些选项的名称为limit
而不是length
。试试这个:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :user_name, :null => false, :limit => 20
t.string :password, :null => false
t.string :email, :null => false, :limit => 30
t.timestamps
end
end
end