This project is archived and is in readonly mode.

#2272 ✓resolved
Denis Defreyne

SQLite / SQLite3 ActiveRecord Adapter should quote table names when renaming tables

Reported by Denis Defreyne | March 17th, 2009 @ 03:26 PM | in 2.x

OVERVIEW

ActiveRecord does not always quote table names when using SQLite3, which may cause migrations to break when using keywords as table names.

STEPS TO REPRODUCE

  1. Create a new rails project.
  2. Create the CreateReferences migration (see below).
  3. Run the db:migrate task.
  4. Create the RenameReferencesToItems migration (see below).
  5. Run the db:migrate task.

The CreateReferences migration:

create_table :references, :force => true do |t|
  t.string :foo
  t.string :bar
  t.timestamps
end

The RenameReferencesToItems:

rename_table :references, :items

ACTUAL RESULTS

Step 3 runs correctly. The "references" table is created.

Step 5 fails to run correctly. This is the output of the rake task:

==  RenameReferencesToItems: migrating =====
-- rename_table(:references, :items)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: near "references": syntax error: ALTER TABLE references RENAME TO items

EXPECTED RESULTS

Step 5 should not fail. It should rename the "references" table to "items". The generated SQL should be

ALTER TABLE "references" RENAME TO items

instead of

ALTER TABLE references RENAME TO items

AFFECTED VERSIONS

  • SQLite3: 3.6.11.
  • ActiveRecord: 2.3.2
  • Ruby: 1.8.7

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages