Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid the implicit sequence on the id field during rails migration

I am attempting to create a table in rails.. I need to be able to set the id's to data that's coming in because I have three (or more) sources, and their ID's must match.
I'm setting the ID's manually, based on data I get in.

When I create the table with a migration, I get the message "will create implicit sequence" I don't want this to happen... How do I avoid it?

I know why it's always there.. but sometimes we need customization no? :)

like image 469
baash05 Avatar asked Oct 21 '25 04:10

baash05


1 Answers

ActiveRecord make the :primary_key column auto_increment by default. Maybe you have to create the primary key by yourself if you don't want it auto_increment.

create_table :table_name, :id => false do |t|
  t.integer :id
  t.timestamps
end
ActiveRecord::Base.connection.execute("ALTER TABLE table_name ADD PRIMARY KEY (id)")
like image 183
Yanhao Avatar answered Oct 23 '25 01:10

Yanhao