Hi, I am doing my first steps with RoR and I have the following problem: I execute my migration file with the following content on a MySQL-database via Rake: <code> class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.integer :id t.string :username, :size => 100 t.string :password, :size => 100 t.string :email, :size => 100 t.timestamps end end def self.down drop_table :users end end </code> I get the following error message by Rake: <code>>rake db:migrate(in D:/InstantRails/rails_apps/EHA) == 1 CreateUsers: migrating ===================================================rake aborted! -- create_table(:users) Mysql::Error: #42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''(11), `username` varchar(255) DEFAULT NULL, `password` varchar(255) DEFAULT NULL'' at line 1: CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), `username` varchar(255) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL) ENGINE=InnoDB (See full trace by running task with --trace)></code> The problem is <code> `id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), </code> - behind "PRIMARY KEY" there is a length defined again. If I execute the statement without this "(11)" behind "PRIMARY KEY", it works. How can I tell Rails how to create the correct statement? -- Posted via http://www.ruby-forum.com/.
ID is a special field in rails, the migrations generate the ID field automatically, you don''t need to declare it within the migration. Thanks & Regards, Dhruva Sagar. Pablo Picasso<http://www.brainyquote.com/quotes/authors/p/pablo_picasso.html> - "Computers are useless. They can only give you answers." On Mon, Aug 31, 2009 at 6:37 PM, Xxx Yyy <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > Hi, > > I am doing my first steps with RoR and I have the following problem: > > I execute my migration file with the following content on a > MySQL-database via Rake: > > <code> > class CreateUsers < ActiveRecord::Migration > def self.up > create_table :users do |t| > t.integer :id > t.string :username, :size => 100 > t.string :password, :size => 100 > t.string :email, :size => 100 > > t.timestamps > end > end > > def self.down > drop_table :users > end > end > </code> > > I get the following error message by Rake: > > <code> > >rake db:migrate > (in D:/InstantRails/rails_apps/EHA) > == 1 CreateUsers: migrating > ===================================================rake aborted! > -- create_table(:users) > > Mysql::Error: #42000You have an error in your SQL syntax; check the > manual that corresponds to your MySQL server version for the right > syntax to use near ''(11), `username` varchar(255) DEFAULT NULL, > `password` varchar(255) DEFAULT NULL'' at line 1: CREATE TABLE `users` > (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), `username` > varchar(255) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, `email` > varchar(255) DEFAULT NULL, `created_at` datetime DEFAULT NULL, > `updated_at` datetime DEFAULT NULL) ENGINE=InnoDB > > (See full trace by running task with --trace) > > > </code> > > The problem is > <code> > `id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), > </code> > > - behind "PRIMARY KEY" there is a length defined again. If I execute the > statement without this "(11)" behind "PRIMARY KEY", it works. How can I > tell Rails how to create the correct statement? > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
2009/8/31 Xxx Yyy <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Hi, > > I am doing my first steps with RoR and I have the following problem: > > I execute my migration file with the following content on a > MySQL-database via Rake: > > <code> > class CreateUsers < ActiveRecord::Migration > def self.up > create_table :users do |t| > t.integer :idYou don''t need the line for id, rails will add it automatically Colin> t.string :username, :size => 100 > t.string :password, :size => 100 > t.string :email, :size => 100 > > t.timestamps > end > end > > def self.down > drop_table :users > end > end > </code> > > I get the following error message by Rake: > > <code> >>rake db:migrate > (in D:/InstantRails/rails_apps/EHA) > == 1 CreateUsers: migrating > ===================================================rake aborted! > -- create_table(:users) > > Mysql::Error: #42000You have an error in your SQL syntax; check the > manual that corresponds to your MySQL server version for the right > syntax to use near ''(11), `username` varchar(255) DEFAULT NULL, > `password` varchar(255) DEFAULT NULL'' at line 1: CREATE TABLE `users` > (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), `username` > varchar(255) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, `email` > varchar(255) DEFAULT NULL, `created_at` datetime DEFAULT NULL, > `updated_at` datetime DEFAULT NULL) ENGINE=InnoDB > > (See full trace by running task with --trace) >> > </code> > > The problem is > <code> > `id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), > </code> > > - behind "PRIMARY KEY" there is a length defined again. If I execute the > statement without this "(11)" behind "PRIMARY KEY", it works. How can I > tell Rails how to create the correct statement? > -- > Posted via http://www.ruby-forum.com/. > > > >