Kevin_20 0 Newbie Poster

I have a MySQL table with a string-based primary key. I created it with an ActiveRecord::Migration as follows:

create_table( "icd9s", id: false) do |t|
   t.string "ICD9Code", limit: 7, null: false
   t.string "ShortDescription", limit: 128, null: false
   t.string "LongDescription",  limit: 255, null: false
end
add_index(:icd9s, :ICD9Code, unique: true)

Then I went into MySQL and flagged "ICD9Code" as primary. When I dumped the schema, I got this:

create_table "icd9s", primary_key: "ICD9Code", force: :cascade do |t|
  t.string "ShortDescription", limit: 128, null: false
  t.string "LongDescription",  limit: 255, null: false
end
add_index "icd9s", ["ICD9Code"], name: "index_icd9s_on_ICD9Code", unique: true, using: :btree

Here's my problem - the schema doesn't indicate that the primary key is not an auto-increment numeric (the Rails standard) so if I have to migrate the database, the table won't be created the same way. Does anybody know how to specify that the string field "ICD9Code" is the primary key i the migration? Also, it this the reason that my relationships between this and other tables doesn't work correctly? (has_one, belongs_to, etc.)

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.