Je veux obtenir la colonne id incrémenter automatique pour un rail create_table commande pour démarrer à 500.Comment définir une valeur d'ID initiale sur une table create_table?
J'ai trouvé des exemples de la façon de définir la valeur identifiant auto_increment initiale sql:
CREATE TABLE student (id int(2) NOT NULL auto_increment, name varchar(50) NOT NULL default '', class varchar(10) NOT NULL default '', mark int(3) NOT NULL default '0', sex varchar(6) NOT NULL default 'male', UNIQUE KEY id (id)) auto_increment=100000 TYPE=MyISAM;
Alors Je regardais l'API Rails et vu ces options sur la méthode create_table:
The options hash can include the following keys:
:id
Whether to automatically add a primary key column. Defaults to true. Join tables for has_and_belongs_to_many should set :id => false.
:primary_key
The name of the primary key, if one is to be added automatically. Defaults to id.
:options
Any extra options you want appended to the table definition.
:temporary
Make a temporary table.
:force
Set to true to drop the table before creating it. Defaults to false.
pas ce que je dois ... J'ai essayé sans succès:
:options => {:auto_increment => 500}
Quelqu'un sait comment obtenir la colonne id incrémenter automatique pour cette déclaration pour commencer à 500:
create_table :contents do |t|
t.string :type, :null => false
t.string :name, :null => false
end
qui l'a fait! Merci! – Matthew
Bon - je n'ai pas vraiment pu le tester quand je l'ai posté! :-) –