Rake Migrate failing - but can't find syntax errors

Hello,

I’m following a guide on creating a migration, but the migrate is
failing due to the following errors:

Line 7: Unexpected ‘\n’ expecting tCOLON2 or ‘{’ or ‘.’
Line 14: $END expecting KEND

But I can’t find any mistakes.

Any help appreciated.

I use sometimes notepad and sometimes crimson editor for my programming
development. If there’s a better editor that would not cause these
problems (as they don’t seem to be typing erors) I’d appreciate the
help.

I pasted this straight from Crimson Editor:

class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.column :title, :string
t.column :body, :text
t.column :created_at, :string
t.lock_version, :integer
end
end

def self.down
drop_table :posts
end
end

H.

This looks strange => t.lock_version, :integer

Is the comma needed?

I’m learning too and have never used t.lock_version.

-Mel

Ok, good news but at the same time bad news.

Good news is that it’s working. I removed the lock_version statement
after loading the file into a windows version of emacs, and also just
removed anything after the last end statement (even though I couldn’t
find anything) and now it migrates fine.

Bad news, I don’t know why the lock_version was having that effect, I
found the statement through google that was supposed to be, well a
locking mechanism to ensure the same database item couldnt be edited at
the same time by two users. I can only suppose it didn’t work. Why I
don’t know.

I hate these types of errors, particularly the $END and KEND as I don’t
know what they mean. I don’t have any other editors than notepad,
Editpad Pro and Crimson Editor, and iit seems that even these put hidden
characters in that mess things up. Any recommendations for a no
nonsense editor would be welcome. I do need something that is
accessible though as I’m partially sighted, so something easy to use.

H.

On Jun 7, 2007, at 6:48 PM, Hussein P. wrote:

I hate these types of errors, particularly the $END and KEND as I
don’t
know what they mean. I don’t have any other editors than notepad,
Editpad Pro and Crimson Editor, and iit seems that even these put
hidden
characters in that mess things up. Any recommendations for a no
nonsense editor would be welcome. I do need something that is
accessible though as I’m partially sighted, so something easy to use.

H.

These are tokens from the parser: kSOMETHING usually means that a
token that looks like something is involved, in this case kEND is the
“end” of some block/loop/if construct. The $ (or $END) often means
the end of the file. They’re not literally “$END” or “kEND” in the
source so your editor will do just fine.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Thanks Chris for clearing that up - at least for me.

–Mel

t.lock_version, :integer

This is definitely the problem. I believe you meant:

t.column lock_version, :integer

However, please don’t add this without actually understanding optimistic
locking. It won’t automatically take care of everything involved with
making sure two people aren’t editing a record at the same time - it
just causes an ActiveRecord::StaleObjectError when trying to save the
record if it has changed since the user loaded it. Your application
still has to handle that error.

For more information:
http://api.rubyonrails.com/classes/ActiveRecord/Locking/Optimistic.html
http://wiki.rubyonrails.org/rails/pages/MagicFieldNames
http://www.ruby-forum.com/topic/61754