# Add\_index error ?cd

**URL:** <https://www.ruby-forum.com/t/add-index-error-cd/184040>\
**Category:** Rails\
**Created:** [February 24, 2010, 5:37am UTC](https://www.ruby-forum.com/t/add-index-error-cd/184040 "2010-02-24T05:37:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lsumnler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/35a633/32.png) [@lsumnler](https://www.ruby-forum.com/u/lsumnler)\
**Post date:** [February 24, 2010, 5:37am UTC](https://www.ruby-forum.com/t/add-index-error-cd/184040/1 "2010-02-24T05:37:28Z")

</div>

Created the following Ruby Migration program 001\_create\_aropenitems.rb

class CreateAropenitems \< ActiveRecord::Migration  
def self.up  
create\_table :aropenitem do |t|  
t.int :cust\_no  
t.date :doc\_date  
t.integer :doc\_no  
t.string :doc\_type, :limit =\> 1  
t.integer :apply\_to\_no  
t.date :doc\_due\_date  
t.decimal :amt1, :precision =\> 9, :scale =\> 2  
t.decimal :amt2, :precision =\> 9, :scale =\> 2  
t.string :ref, :limit =\> 30  
t.int :slsmn1  
t.int :slsmn2  
t.int :slsmn3  
t.decimal :amt3, :precision =\> 7, :scale =\> 2  
t.int :city\_county\_tax  
end  
add\_index(:aropenitem, [:cust\_no, :doc\_date, :doc\_no, :doc\_type],  
:unique =\> true, :name =\> ‘cust\_doc’)  
add\_index(:aropenitem, [:apply\_to\_no, :cust\_no], :name =\>  
‘apply\_to’)  
add\_index(:aropenitem, :city\_county\_tax, :name =\> ‘texas\_tax’)  
end

def self.down  
drop\_table :aropenitems

end  
When I run rake I get the following trace:

# lenyel@lenyel-laptop:~/bruskerb$ rake --trace (in /home/lenyel/bruskerb) \*\* Invoke default (first\_time) \*\* Invoke migrate (first\_time) \*\* Invoke environment (first\_time) \*\* Execute environment \*\* Execute migrate == CreateAropenitems: migrating

– create\_table(:aropenitem)  
-\> 0.1718s  
– add\_index(:aropenitem, [:cust\_no, :doc\_date, :doc\_no, :doc\_type],  
{:unique=\>true, :name=\>“cust\_doc”})  
rake aborted!  
An error has occurred, all later migrations canceled:

Mysql::Error: Key column ‘cust\_no’ doesn’t exist in table: CREATE UNIQUE  
INDEX `cust_doc` ON `aropenitem` (`cust_no`, `doc_date`, `doc_no`,  
`doc_type`)  
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active\_record/connection\_adapters/abstract\_adapter.rb:219:in  
`log’

Don’t understand why I would be getting thie error.

MySQL version 5.1.37  
activerecord 2.3.5  
mysql 2.8.1

Thanks  
Len

---

<div class="post-metadata">

**Author:** ![lsumnler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/35a633/32.png) [@lsumnler](https://www.ruby-forum.com/u/lsumnler)\
**Post date:** [February 24, 2010, 8:23am UTC](https://www.ruby-forum.com/t/add-index-error-cd/184040/2 "2010-02-24T08:23:33Z")

</div>

Are u sure the table created with the field ‘cust\_no’ ?  
If it exists?  
Execute the query which is in the log for creating index inside your  
mysql account and check the reason for the error.

Revert back me if u find any solution for it.

Thank you.

---

<div class="post-metadata">

**Author:** ![lsumnler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/35a633/32.png) [@lsumnler](https://www.ruby-forum.com/u/lsumnler)\
**Post date:** [February 24, 2010, 12:02pm UTC](https://www.ruby-forum.com/t/add-index-error-cd/184040/3 "2010-02-24T12:02:21Z")

</div>

Hello,

Here’s my version of your migration file: [gist:313327 · GitHub](http://gist.github.com/313327)

Changed t.int to t.integer as i dont think rails understand int as in  
integer (maybe i’m wrong here). Although changed table name to  
aropenitems so it’s in plural all over migration file.

At least now this migration completes sucessfully…

---

<div class="post-metadata">

**Author:** ![lsumnler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/35a633/32.png) [@lsumnler](https://www.ruby-forum.com/u/lsumnler)\
**Post date:** [February 24, 2010, 2:46pm UTC](https://www.ruby-forum.com/t/add-index-error-cd/184040/4 "2010-02-24T14:46:03Z")

</div>

Ugis Ozols wrote:

> Hello,
> 
> Here’s my version of your migration file: [gist:313327 · GitHub](http://gist.github.com/313327)
> 
> Changed t.int to t.integer as i dont think rails understand int as in  
> integer (maybe i’m wrong here). Although changed table name to  
> aropenitems so it’s in plural all over migration file.
> 
> At least now this migration completes sucessfully…

Hello,

That was exactly the problem. I just had looked at it so long. Your are  
the man.

Thanks you for your time and effort.  
Len
