ich die automatische Inkrementieren id Spalte für ein create_table Schienen bekommen Befehl bei 500Wie wird ein initialer ID-Wert für eine create_table gesetzt?
Ich habe festgestellt, Beispiele zu beginnen, wie die anfängliche auto_increment ID-Wert in SQL einzustellen:
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;
So ich schaute auf die Rails API und sah diese Optionen auf der create_table Methode:
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.
Nicht das, was ich brauche ... ich habe versucht, dies ohne Erfolg:
:options => {:auto_increment => 500}
Wer weiß, wie die automatische Inkrementieren id Spalte für diese Erklärung bekommen bei 500 zu starten:
create_table :contents do |t|
t.string :type, :null => false
t.string :name, :null => false
end
Das tat es! Vielen Dank! – Matthew
Gut - ich konnte es nicht wirklich testen, als ich es gepostet habe! :-) –