Simple message board: syntax error, unexpected tCONSTANT,

Hi all

Im trying to make a simple message board using this tutorial

However I have hit a problem when I do rake db:migrate it has a problem
with the post_table migrate file, any help with this would be great.

./db/migrate//002_create_posts_table.rb:10: syntax error, unexpected
tCONSTANT,
expecting kEND
FOREIGN KEY(discussion_id) REFERENCESdiscussions(id)

class CreatePostsTable < ActiveRecord::Migration
def self.up
create_table :posts do |table|
table.column :body, :text
table.column :created_at, :datetime, :null => false
table.column :name, :string, :limit=>100
table.column :discussion_id, :integer, :null => false
end
execute ALTER TABLE posts ADD CONSTRAINT fk_posts
FOREIGN KEY(discussion_id) REFERENCES discussions(id)
end
def self.down
drop_table :posts
end
end

Alan Red wrote:

execute ALTER TABLE posts ADD CONSTRAINT fk_posts
FOREIGN KEY(discussion_id) REFERENCES discussions(id)

A migration is just Ruby code and this is not Ruby.

I suspect you want:

execute “ALTER TABLE posts ADD CONSTRAINT fk_posts
FOREIGN KEY(discussion_id) REFERENCES discussions(id)”

I suspect the quotes got stripped out when the snippet was displayed in
the article. Along with the indentation.

Mark B. wrote:

Alan Red wrote:

execute ALTER TABLE posts ADD CONSTRAINT fk_posts
FOREIGN KEY(discussion_id) REFERENCES discussions(id)

A migration is just Ruby code and this is not Ruby.

I suspect you want:

execute “ALTER TABLE posts ADD CONSTRAINT fk_posts
FOREIGN KEY(discussion_id) REFERENCES discussions(id)”

I suspect the quotes got stripped out when the snippet was displayed in
the article. Along with the indentation.

Thanks for this, still a newbie at ruby on rails but starting to enjoy
using it. Much more easier than php.

Now the quotes are there I can understand why this wouldn’t really be
ruby code.