运行 bin/rake db:migrate 时报
-- create_table(:btpzs)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
undefined method `int' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x007f24c63b6900>/root/haonan_file/dvd/bpdvds/bp/db/migrate/20150918095902_create_btpzs.rb:4:in `block in change'
/root/haonan_file/dvd/bpdvds/bp/db/migrate/20150918095902_create_btpzs.rb:3:in `change'
-e:1:in `<main>'
NoMethodError: undefined method `int' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x007f24c63b6900>
/root/haonan_file/dvd/bpdvds/bp/db/migrate/20150918095902_create_btpzs.rb:4:in `block in change'
/root/haonan_file/dvd/bpdvds/bp/db/migrate/20150918095902_create_btpzs.rb:3:in `change'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
这个代码
class CreateBtpzs < ActiveRecord::Migration
def change
create_table :btpzs do |t|
t.int :id
t.string :ids
t.string :dvd_name
t.string :new_data
t.text :jianjie
t.string :img_min
t.text :img
t.string :url
t.timestamps null: false
end
end
end
当我把 int 改成 integer 的时候 又会报
== 20150918095902 CreateBtpzs: migrating ======================================
-- create_table(:btpzs)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
you can't redefine the primary key column 'id'. To define a custom primary key, pass { id: false } to create_table./root/haonan_file/dvd/bpdvds/bp/db/migrate/20150918095902_create_btpzs.rb:4:in `block in change'
/root/haonan_file/dvd/bpdvds/bp/db/migrate/20150918095902_create_btpzs.rb:3:in `change'
-e:1:in `<main>'
ArgumentError: you can't redefine the primary key column 'id'. To define a custom primary key, pass { id: false } to create_table.
/root/haonan_file/dvd/bpdvds/bp/db/migrate/20150918095902_create_btpzs.rb:4:in `block in change'
/root/haonan_file/dvd/bpdvds/bp/db/migrate/20150918095902_create_btpzs.rb:3:in `change'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
root@iZ28zli8s44Z:~/haonan_file/dvd/bpdvds/bp# sudo svn up
Updating '.':
U db/migrate/20150918095902_create_btpzs.rb
Updated to revision 213320.