Duplicate entry '...' for key 'PRIMARY' for long id field #7420

Closed
wafcio opened this Issue Aug 22, 2012 · 3 comments

Comments

Projects
None yet
3 participants
@wafcio

wafcio commented Aug 22, 2012

I need add to id values with 15 digits, it is id from facebook objects and it is not depent on me. First I changed int to string, it works in browser. But in test with capybara it not work, even if I drop, create and migrate test database once more. So next I will change string to integer but with limit 8 (I'm using mysql)

Instead of this, when I tried saved long number in integer I got duplicate entry error from mysql (strange).

But what is the problem when I changed id from int to string, in test (after load schema.rb file) id field in sql query was still like integer and schema.rb file not have any information about id type (string). And after changed id to integer with limit 8, schema.rb didn't have information about this too. It is very bad, because after migration id is big int but after load schema id is only integer

Summing up:
schema.rb are able to create primary key only as integer. it would be grate to support other datatype for primary key

@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Sep 21, 2012

Member

I feel like this is a duplicate, but I just can't find the ticket. :(

Member

steveklabnik commented Sep 21, 2012

I feel like this is a duplicate, but I just can't find the ticket. :(

@senny

This comment has been minimized.

Show comment
Hide comment
@senny

senny Nov 11, 2012

Member

I'm not sure if I understand the issue completely. You could try to define the primary key as follows:

class Article < ActiveRecord::Base
  self.primary_key = "string_pk"
end

class CreateArticles < ActiveRecord::Migration
  def change
    create_table :articles, :id => false do |t|
      t.string :string_pk, :primary => true

      t.timestamps
    end
  end
end

If this does not help could you please provide a test-case or a sample app with your problem? This would help a lot to investigate the problem. Also, what version of rails do you use?

Member

senny commented Nov 11, 2012

I'm not sure if I understand the issue completely. You could try to define the primary key as follows:

class Article < ActiveRecord::Base
  self.primary_key = "string_pk"
end

class CreateArticles < ActiveRecord::Migration
  def change
    create_table :articles, :id => false do |t|
      t.string :string_pk, :primary => true

      t.timestamps
    end
  end
end

If this does not help could you please provide a test-case or a sample app with your problem? This would help a lot to investigate the problem. Also, what version of rails do you use?

@senny

This comment has been minimized.

Show comment
Hide comment
@senny

senny Jan 12, 2013

Member

We havent heard from you in 2 months. Without further information we can't pursue the issue further. I'm closing this for now. Please reopen if the problem still occurs and post more information.

Member

senny commented Jan 12, 2013

We havent heard from you in 2 months. Without further information we can't pursue the issue further. I'm closing this for now. Please reopen if the problem still occurs and post more information.

@senny senny closed this Jan 12, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment