Rails G Migration Doesn't Work

Rails g migration doesn't work

You are not running it inside a rails generated project directory. You are running it outside it.

EDIT: It could also be if the script folder is missing. Or the rails script is missing inside the script folder if you are executing it inside the project folder.

Rails g migration goes new line and does nothing

It is spring problem. This problem appears due to interrupting $ rails generate command.

To solve it you should stop all spring processes:

$ spring stop

And then:

$ rails generate

You can find more details here https://github.com/rails/rails/issues/13381

Rails Migration doesn't create anything

It turns out that I misplaced my bin folder. It was contained within my 'app' folder. I cut/pasted my bin folder back into the app's root directory, and now the migration works fine.

Why rake db:migrate doesn't work when adding Admin to User?

"PG::DuplicateColumn: ERROR: column "admin" of relation "users" already exists"

The error message is very clear. You already have an admin column in your users table. You have to remove that before you can add admin column to your users table.

To remove the already existing admin column, generate a migration:

rails g migration RemoveAdminFromUsers admin:boolean

then run the migration to remove the admin from users:

rake db:migrate

Now you can add it back again:

rails g migration AddAdminToUsers admin:boolean

Rails | Migration missing | Works locally but not on Heroku

I solved it with your help, Mark! :-)

I did the following:

1) Roll back migrations

I ran rails db:migrate:status and saw that I should roll back two migrations to get completely clean of my attempts to add/remove the end_date column.

When I tried to rollback, it gave me an error that my remove column migrations weren't reversible. I had to enter the type of column. So I added that as a third parameter. Example: remove_column :events, :end_date, :date

After that a rollback was possible. The easiest way was to run rails db:rollback STEP=2.

2) Delete down migrations and check schema

After rolling back my migrations, I deleted the unneeded migration-files from the folder. Also, I checked my schema file and manually removed the end_date row from the model.

3) Create conditional remove row migration

Using Mark's answer, I added a new migration with the following code:

class AddEndDateToEvents < ActiveRecord::Migration[5.2]
def change
remove_column(:events, :end_date) if column_exists?(:events, :end_date)
add_column :events, :end_date, :date
end
end

4) Reset database and run db:migrate

I then did my git push && git push heroku and then I ran heroku restart && heroku pg:reset DATABASE --confirm APP-NAME && heroku run rake db:migrate, where APP-NAME was the name of my app.

And now it works! :-)

Thank you very much. I'm quite blown away by the quick and helpful response, and the fact that some person out there on the interwebs took the time to edit my post and format it nicely.

Generous community. Nice!

No migration after running db:migrate

Creating the model is not enough, you also need to create a migration that creates the book yourself.

In this case you should run rails g migration CreateBooks which will create the migration that adds the table. Then you can run rails db:migrate and your model will work the way it is supposed to.

More info on migrations: Here

rails migration doesn't update database

You need to specify the reference in migration as well. The reference is added to the table which has the foreign key.

class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
t.string :name
t.datetime :start_date
t.datetime :end_date
t.boolean :active

t.references :client # Add this line

t.timestamps
end
end
end

rake db:migrate doesn't work (Rails 4.0.4)

OK, so the problem was that Devise generator generated ".txt" file with migration instead of ".rb" file. Strange, but changing extension solved it.



Related Topics



Leave a reply



Submit