ActiveRecord::JDBCError

I just created a new rails 3.0.6 application. I’m using mysql.

After doing a jruby -S rake db:create:all and then creating a simple
model and associated migration, I attempt to run jruby -S rake
db:migrate and it pukes:

ActiveRecord::JDBCError: Table ‘afm_dev.state_points’ doesn’t exist:
ALTER TABLE state_points ADD pvalue int(11)

The best I can see is it’s not creating the table, and hence it can’t
run the ALTER TABLE SQL command.

I’m running
jruby 1.6.0,
activerecord-jdbc-adapter (1.1.1),
jdbc-mysql (5.1.13)

I’ve googled around a bit but don’t see anything about why this might be
failing. Any ideas?

-Jim

There’s likely a problem in your migration. Can you post it here?

  • Justin

Justin C. wrote in post #991559:

There’s likely a problem in your migration. Can you post it here?

  • Justin

class CreateStatePoints < ActiveRecord::Migration
def self.up
create_table :state_points do |t|
add_column :pvalue, :integer
add_column :state_points, :parea, :decimal, :precision => 15,
:scale => 10
add_column :state_points, :pmean, :decimal, :precision => 15,
:scale => 10
add_column :state_points, :lifeform, :string
add_column :state_points, :state_abbr, :string
add_column :state_points, :comp_date, :date
t.timestamps
end
end

def self.down
drop_table :state_points
end
end

Thanks,
-Jim

Don’t use add_column within the the create_table block. That’s to add
a column to an existing table.

instead use:

t.column :pvalue, :integer

  • Justin

Justin C. wrote in post #991563:

Don’t use add_column within the the create_table block. That’s to add
a column to an existing table.

instead use:

t.column :pvalue, :integer

  • Justin

Yep, realized it about 30 seconds after posting my migration…

Thanks though,
-Jim

Jim W. wrote in post #991560:

Justin C. wrote in post #991559:

There’s likely a problem in your migration. Can you post it here?

  • Justin

class CreateStatePoints < ActiveRecord::Migration
def self.up
create_table :state_points do |t|
add_column :pvalue, :integer
add_column :state_points, :parea, :decimal, :precision => 15,
:scale => 10
add_column :state_points, :pmean, :decimal, :precision => 15,
:scale => 10
add_column :state_points, :lifeform, :string
add_column :state_points, :state_abbr, :string
add_column :state_points, :comp_date, :date
t.timestamps
end
end

def self.down
drop_table :state_points
end
end

Thanks,
-Jim

CRAP!!!

I just looked at that again… and duh, wrong syntax for creating a new
table. Wow, I need to pay more attention.

Thanks for asking me to post that. It actually helped.

-Jim