ruby-on-rails – 在rails上创建ruby的新表
发布时间:2020-12-16 19:41:38 所属栏目:百科 来源:网络整理
导读:我尝试在rails中创建一个新的表.我发现和尝试悲伤的每一个例子都不适合我 所以这就是我现在所尝试的:(我使用 Ruby版本1.9和Rails版本3.2.13 在终端中建立新的模式: rails generate model content content_id:auto-generated,law_id:integer,parent_id:inte
我尝试在rails中创建一个新的表.我发现和尝试悲伤的每一个例子都不适合我
所以这就是我现在所尝试的:(我使用 Ruby版本1.9和Rails版本3.2.13 在终端中建立新的模式: rails generate model content content_id:auto-generated,law_id:integer,parent_id:integer,titel:string,text:string,content:string,url:string 生成以下代码: class CreateContents < ActiveRecord::Migration def change create_table :contents do |t| t.auto-generated,:content_id t.integer,:law_id t.integer,:parent_id t.string,:titel t.string,:text t.string,:content t.string :url t.timestamps end end end 如果我尝试耙db:migrate我收到以下错误消息: syntax error,unexpected ',',expecting keyword_end t.auto-generated,:content_id ^ 如果我删除“,”我得到这个错误信息: syntax error,unexpected tSYMBEG,expecting keyword_do or '{' or '(' t.auto-generated :content_id ^ 我的研究让我也以这种方式创建一个表: class CreateContents < ActiveRecord::Migration def change create_table :contents do |t| t.auto-generated "content_id" t.integer "law_id" t.integer "parent_id" t.string "titel" t.string "text" t.string "content" t.string "url" t.timestamps end end end 如果我试图用这个例子耙数据分析器,我得到这个错误信息: syntax error,unexpected tSTRING_BEG,expecting keyword_do or '{' or '(' t.auto-generated "content_id" ^ 我做错了什么 解决方法
自动生成不是支持的列类型.
Active Record支持以下数据库列类型: :binary :boolean :date :datetime :decimal :float :integer :primary_key :string :text :time :timestamp http://guides.rubyonrails.org/migrations.html#supported-types的更多信息 Rails将自动为您创建列ID,因此只需将迁移编辑为以下内容即可 class CreateContents < ActiveRecord::Migration def change create_table :contents do |t| t.integer "law_id" t.integer "parent_id" t.string "titel" t.string "text" t.string "content" t.string "url" t.timestamps end end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |