ruby on rails - SQLite3::SQLException: near "CONSTRAINT": syntax error -


Can you help me with this problem? First of all I have created a migration that generates three tables. Then I try to execute a SQL query but for some reason an error has started. I'm a newbie. I'm reading this rail guide in four editions (4.0.6 rubles on-rail)

< Pre> class examples migration & lt; ActiveRecord :: migration def up_table: Categories | T | Make the end_table: User | T | T.string: email end create_table: products do | T | T.references: Follow the End of the Series & lt; & Lt; -SQL ALTER TABLE products add constraint foreign key (category_id) fk_products_categories categories (ID) SQL add_column manual user ,: HOME_PAGE_URL ,: string rename_column: The users ,: email ,: EMAIL_ADDRESS end def liter; # Execute a foreign key below and adding lt leave -SQL ALTER TABLE products foreign key fk_products_categories SQL rename_column: The users ,: EMAIL_ADDRESS ,: email remove_column: The users ,: HOME_PAGE_URL drop_table: products drop_table: those drop_table: products end

Ubuntu console

  Trabajo @ Fernando: ~ / estudio / MigrationsGuides $ rake db: drop Trabajo @ Fernando: ~ / estudio / MigrationsGuides $ rake db: migrate == ExampleMigration : Migrate =============================================== - - create_table (categories) - & gt; 0.0019s - create_table (user) - & gt; 0.0012 - Create_table ((product) - & gt; 0.0007s - Execute ("optional table product \ nadded integration fk_products_categories \ n foreign key (category_id) \ n reference categories (id \ n") rack was aborted! StandardError: An error has occurred, this and all subsequent migration canceled: SQLite3 :: SQLException: Closer "Handicap": Syntax Error: Change the table to add products to the barrier Foreign key (category_id) fk_products_categories Reference categories (ID) / home /trabajo/.rvm /gems/ruby-2.0.0-p481@MigracionesGuides/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `Start '/home/trabajo/.rvm/gems/ ruby-2.0.0 -p481@MigracionesGuides/gems/sqlite3-1.3.9/lib/sqlite3/database.rb: 91: `new'/home/trabajo/.rvm/gems/ruby-2.0.0-p481@MigracionesGuides / gems / sqlite3 in -1.3.9 / lib / sqlite3 / database.rb: 91: `ready'/home/trabajo/.rvm/gems/ruby-2.0.0-p481@MigracionesGuides/gems/sqlite3-1.3.9 In / lib / sqlite3 /database.rb:134:IN 'execute'  

to:

Note: Enable foreign key support

In order to use foreign key constraints in SQLite, the library must be compiled with the name SQLITE_OMIT_FOREIGN_KEY < / Code> or SQLITE_OMIT_TRIGGER defined [...] If OMIT_FOREIGN_KEY is defined, then foreign key definitions can not be parsed (specifying a foreign key definition Try cinta S error).

It looks like your SQLite was compiled with OMIT_FOREIGN_KEY defined or recompile SQLite with the FBI and enabled or (Improved IMO) one Install the appropriate database that fully supports FKs outside the box and switches to that database; I recommend PostgreSQL but MySQL should do this already.

In any case, always develops on top of the same database you are going to deploy; It also applies to things that you are hacking to play, the database you use will give you habits and will not take those habits to another database. The ORM providing database portability is a myth, do not come for it.


Comments

  1. Your blog is in a convincing manner, thanks for sharing such an information with lots of your effort and time
    ruby on rails training
    ruby on rails training India
    ruby on rails training Hyderabad

    ReplyDelete

Post a Comment

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -