# Help with primary\_key\_prefix\_type

**URL:** <https://www.ruby-forum.com/t/help-with-primary-key-prefix-type/134183>\
**Category:** Rails\
**Created:** [April 8, 2008, 5:53pm UTC](https://www.ruby-forum.com/t/help-with-primary-key-prefix-type/134183 "2008-04-08T17:53:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 8, 2008, 5:53pm UTC](https://www.ruby-forum.com/t/help-with-primary-key-prefix-type/134183/1 "2008-04-08T17:53:56Z")

</div>

I put this config in environment.rb

# Use table\_id instead of id for primary key.

config.active\_record.primary\_key\_prefix\_type =  
:table\_name\_with\_underscore

I have this migration:

class CreateEntities \< ActiveRecord::Migration  
def self.up  
create\_table :entities do |t|  
t.string :entity\_name, :null =\> false,  
:limit =\> 40  
t.string :entity\_legal\_name, :null =\> false,  
:limit =\> 120  
t.string :entity\_legal\_form, :null =\> false,  
:limit =\> 4

```
  t.timestamps
end

add_index :entities, :entity_name,
          :name => :idxU_entities_entity_name,
          :unique => true

```

end

def self.down  
remove\_index :entities, :name =\> :idxU\_entities\_entity\_name  
drop\_table :entities  
end  
end

When I run these rake tasks:

rake db:drop  
rake migrate

Then I see this:

# sqlite3 db/development.sqlite3

SQLite version 3.3.6  
Enter “.help” for instructions  
sqlite\> .schema entities  
CREATE TABLE entities (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,  
“entity\_name” varchar(40) NOT NULL, “entity\_legal\_name” varchar(120) NOT  
NULL, “entity\_legal\_form” varchar(4) NOT NULL, “created\_at” datetime  
DEFAULT NULL, “updated\_at” datetime DEFAULT NULL);

But I expected to see this:

CREATE TABLE entities (“entity\_id” INTEGER PRIMARY KEY AUTOINCREMENT NOT  
NULL,…

It makes no difference if I pass the value to  
config.active\_record.primary\_key\_prefix\_type as a string or a symbol as  
neither works.

So, what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 8, 2008, 6:17pm UTC](https://www.ruby-forum.com/t/help-with-primary-key-prefix-type/134183/2 "2008-04-08T18:17:27Z")

</div>

James B. wrote:

> So, what am I doing wrong?

Nothing apparently, see Ticket #10314 (closed defect: fixed).

My next question is how do I get this fix into my (gem) copy of Rails:

Changeset 9057  
View differences  
Show lines around each change  
Ignore:  
Blank lines  
Case changes  
White space changes

Timestamp:  
03/18/08 18:36:11 (3 weeks ago)  
Author:  
bitsweat  
Message:

```
Merge [9056] from trunk: Migrations: create_table supports 

```

primary\_key\_prefix\_type. References #10314.  
Files:

```
    *
      branches/2-0-stable/activerecord/CHANGELOG (modified) (1 diff)
    *
      branches/2-0-stable/activerecord/lib/active_record/base.rb 

```

(modified) (1 diff)  
\*  
branches/2-0-stable/activerecord/lib/active\_record/connection\_adapters/abstract/schema\_statements.rb  
(modified) (1 diff)

Do I have to checkout and freeze 2-0-stable in vendor plugins?
