Add_index error ?cd

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

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.

Hello,

Here’s my version of your migration file: gist:313327 · GitHub

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…

Ugis Ozols wrote:

Hello,

Here’s my version of your migration file: gist:313327 · GitHub

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