I created a model called customer. The migrate file is as follows:-
class CreateCustomers < ActiveRecord::Migration[5.0]
def change
create_table :customers , :primary_key => :customer_id , do |t|
t.integer :customer_id
t.string :first_name
t.string :last_name
t.string :address_1
t.string :address_2
t.string :city
t.string :state
t.bigint :postal_code
t.timestamps
end
end
end
Now when I run rails db:migrate, this is the error that I get:-
rails aborted!
SyntaxError: /home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/db/migrate/20170428100848_create_customers.rb:3: syntax error, unexpected keyword_do_block
imary_key => :customer_id , do |t|
^
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/db/migrate/20170428100848_create_customers.rb:4: syntax error, unexpected tSYMBEG, expecting keyword_end
t.integer :customer_id
^
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/db/migrate/20170428100848_create_customers.rb:16: syntax error, unexpected keyword_end, expecting end-of-input
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/bin/rails:9:in `require'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/bin/rails:9:in `<top (required)>'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
The schema.rb file has no sign of the customer table either. Can someone help? EDIT: After removing the comma after customer_id I'm getting these:-
== 20170428100848 CreateCustomers: migrating ==================================
-- create_table(:customers, {:primary_key=>:customer_id})
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
you can't redefine the primary key column 'customer_id'. To define a custom primary key, pass { id: false } to create_table.
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/db/migrate/20170428100848_create_customers.rb:4:in `block in change'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/db/migrate/20170428100848_create_customers.rb:3:in `change'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/bin/rails:9:in `require'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/bin/rails:9:in `<top (required)>'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
ArgumentError: you can't redefine the primary key column 'customer_id'. To define a custom primary key, pass { id: false } to create_table.
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/db/migrate/20170428100848_create_customers.rb:4:in `block in change'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/db/migrate/20170428100848_create_customers.rb:3:in `change'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/bin/rails:9:in `require'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/bin/rails:9:in `<top (required)>'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)