Jason Manduoua
Jason Manduoua

Reputation: 25

Illegal name for migration file

I'm trying to generate a new user model, and I could have sworn that this worked before

$ rails generate migration User.rb

but now it complains that this is illegal. I keep getting an error:

Illegal name for migration file: user.rb (only lower case letters, numbers, and '_' allowed)

As you can see user.rb is only lowercase.

Upvotes: 1

Views: 1520

Answers (3)

Surya
Surya

Reputation: 15992

Actually, issue here is with . which you have between User and rb, i.e.: User.rb. If you change it to: rails generate migration Userrb then it should work.

However, you can be more efficient while generating a migration by following a small convention:

  • To create users table:

    $ rails generate migration create_users

    or:

    $ rails generate migration CreateUsers

  • To have some columns while creating users table:

    $ rails generate migration create_users name:string email:string address:text

    or:

    $ rails generate migration CreateUsers name:string email:string address:text

UPDATE: Apologies for not consider your line: generate a new user model. If you want to generate a model then you can run these convenient commands:

  • To create User model which will also create users table migration by default:

    $ rails generate model user

    or:

    $ rails generate model User

  • To create User model which will also create users table migration with some attributes by default:

    $ rails generate model user name:string email:string address:text

    or:

    $ rails generate model User name:string email:string address:text

Upvotes: 4

Saurabh
Saurabh

Reputation: 1104

Migrations should be like this.

rails generate migration add_email_to_users email:string

I don't know what are trying to achieve by User.rb. Although refer this doc. Its a good start if you are not aware of how migrations work.

Upvotes: 0

sn0wtroopeer
sn0wtroopeer

Reputation: 102

Change to user instead of User.rb.

Upvotes: 0

Related Questions