Syntax errors on "insert into"


#1

I’m digging around and googling but can’t seem to find what I think is a
simple thing. All I’m trying to do is insert data in a migration into a
table, using regular SQL statements.

LIke this:

class AddStateData < ActiveRecord::Migration
def self.up

INSERT INTO states values (’’,‘Alaska’);
INSERT INTO states values (’’, ‘Arkansas’);
INSERT INTO states VALUES (’’, ‘Arizona’);
INSERT INTO states VALUES (’’, ‘California’);
INSERT INTO states VALUES (’’, ‘Colorado’);
INSERT INTO states VALUES (’’, ‘Connecticut’);
INSERT INTO states VALUES (’’, ‘District of Columbia’);
INSERT INTO states VALUES (’’, ‘Delware’);
INSERT INTO states VALUES (’’, ‘Florida’);
INSERT INTO states VALUES (’’, ‘Georgia’);
INSERT INTO states VALUES (’’, ‘Hawaii’);

Pretty simple i think, but in RadRails it shows multiple syntax errors.

Anyone mind telling me what’s wrong ?

TIA
Stuart


#2

“Dark” == Dark A. removed_email_address@domain.invalid writes:

Anyone mind telling me what’s wrong ?

You’re putting wodges of one programming language into code written in
another one. What on Earth made you think you could just start putting
SQL into your Ruby program?

	     Calle D. <removed_email_address@domain.invalid>
	 http://www.livejournal.com/users/cdybedahl/
	"Let me answer that question with a headbutt."
	      -- Buffy, Buffy the Vampire Slayer

#3

Good question, with the only answer right now being “I just assume” :wink:
So, I’ll try doing something like this:

State.create(:state => ‘New York’,

Stuart


#4

Interestingly enough once I got the migration code correct I found out
that
there needs to be a model in place . I had made the error of creating
the
create table migration code first, then the add data for the table. Once
I
created the model though I see it wanted to make the migration for
creating
the table but didn’t override the existing file. Once the model was in
place I could add the data to the table.

Sorry, I’m rambling.
Stuart