Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Make SchemaDumper dump primary keys not named 'id' correctly in SQLite3

#1153

Consider this schema:


create_table :pets, :primary_key => :pet_id ,:force => true do |t|
  t.string :name
  t.integer :owner_id, :integer
end

This gets incorrectly dumped like the following when using SQLite3 (:pet_id is no longer a pk):


create_table "pets", :id => false, :force => true do |t|
  t.integer "pet_id",   :null => false
  t.string  "name"
  t.integer "owner_id"
  t.integer "integer"
end

This patch fixes this so the output is correct:


create_table "pets", :primary_key => "pet_id", :force => true do |t|
  t.string  "name"
  t.integer "owner_id"
  t.integer "integer"
end

We ran into this bug when developing against a legacy database schema. We wanted the test and development environments to run against SQLite3 and production against SQL Server (yikes).

The original fix was found in the old Trac - Ticket 6095

The fix can be cherry-picked from Git in this commit

Reported by Aslak Hellesøy · October 2nd, 2008 @ 07:14 AM

State: stale
Milestone: 3.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Matt Scilipoti
    Matt Scilipoti

    The fix listed in the referenced fork on Git worked for me. Still needed in Rails 2.2.2.

    January 14th, 2009 @ 09:31 PM

  2. Pratik
    Pratik
    • Assigned user set to Pratik
    • State changed from new to incomplete
    • I get failing test on MySQL after applying the patch.
    • Could you please upload a patch using git-format-patch ?

    Thanks.

    March 10th, 2009 @ 05:34 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from incomplete to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:04 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:04 PM