I am using c9 IDE.
The command I entered in the terminal: bundle exec rails generate migration CreateContacts.
I get a message: error: could not find 'rails'.
This is the command in Nitrous, is there a different command in cloud9?
Is there a step-by-step procedure to manually create the rails migration CreateContacts in the File Directory in cloud9? What code is entered into the newly created files. I notice in the Rails Guide a a file is generated e.g. number (YYYYMMDDHHMMSS)_create_contacts.rb, if this file is manually created will this number e.g. (20160928130510)_create_contacts.rb - be correct and what code is entered into the file?
I'm pretty stuck here and need some expert guidance on this one please.
I use cloud9 IDE as well and when i want to create a migration file i simply do rails generate migration . (I dont include bundle exec in the command)
The file generated in the migration folder will be created in the YYYYMMDDHHMMSS format.
Related
After upgrading to Rails 5, I receive an error message like following every time I try to load from schema (set up a new computer on the app, run rails db:test:prepare before running tests, etc.):
ActiveRecord::StatementInvalid: PG::UndefinedObject: ERROR: type "serial" does not exist
LINE 1: SELECT 'serial'::regtype::oid
Searching around isn't yielding much help. The most relevant thread is this one: https://github.com/rails/rails/issues/30298 but I am not trying to run any new migrations, nor does the schema_plus_indexes gem seem to have anything to do with the issue (the two issues described in that thread).
In our case, we don't keep migration files around after they have been run against all databases. Because of this, when working on the upgrade to rails 5, there were 0 migration files present. The issue, it seems, is that rails will only automatically "fix" your schema.rb file for you if you are actually running a migration file (even trying rails db:migrate with no migration files present won't work).
The solution, for us, was to create a blank migration and run rails db:migrate in order to get the schema.rb file properly formatted.
I am working through the Michael Hartl tutorial
I have created a migration file called add_remember_token_to_users and filled it with the contents from listing 8.16 in order to create a remember_token cell, which is indexed, for each user.
I migrated the data, from the command line, which, according to the cmd, ran successfully. However, I am looking at the test.sqlite3 file with a splite browser and it has not updated to include a remember_token cell. What is going on?
I don't see any typos in my migration file and I generated the migration file using rails.
You need to apply the migration to the test database as well, because the migration only updated the development database. You can achieve it using the following command:
rake db:test:clone_structure # Recreate the test databases from the development structure
Note that there are other ways to achieve the same results such as running just the clone if you are wondering:
db:test:clone
I am new to rails.
I want to create an Article model. So I run,
rails g model Article name:string context:string
Instead of content I type in context, Is there a way to update the schema.rb file that gets generated?
I would like the articles table to have name and content columns.
Don't focus on schema.rb -- this is just a dump of the current state of your database. Instead, what you need to do is correct the migration file. It is the migration files that actually define what tables/column will exist in production in the end so they must be correct. I'd recommend:
Run ls -ltr db/migrate -- use this to find your migration file and copy the date string. Rails uses this as the "version" of the migration. For example: "20140809165359_create_articles", the version is "20140809165359".
Run bundle exec rake db:migrate:down VERSION=20140809165359 (replace the version number with your own, here)
Now go fix your migration file (change "context" to "content")
Run bundle exec rake db:migrate to migrate back up.
This will fix the underlying problem and you'll notice that now, after migrating back up, your schema.rb will be fixed too.
I ran a rails g migration rename_user_id_columns and it says:
invoke active_record
create db/migrate/20140617192830_rename_user_id_columns.rb
The problem is this file does not actually exist in the folder, and also I ran a search on my whole computer and couldn't find it. Interestingly, when I try to then create the file manually in Sublime and save, it tells me I'm going to be overwriting an existing file. Whenever I try to run the manual migration, I get the following error.
rake aborted!
NameError: uninitialized constant RenameUserIdColumns
A restart of the computer fixed this problem for me. But I think going to Project > Refresh Sublime could do the trick as well.
I've created a file ebm.rb script to add new entries to a database in rails.
The file is very long, and uses some rails models.
Can I easily execute ebm.rb in the rails console?
I tried something with load and require, but that didn't work. My ebm.rb file is located in C:\Sites\ebm and my rails project in C:\Sites\rublesql.
You can run the code in the file in the context of your rails app with
rails runner
http://guides.rubyonrails.org/command_line.html#rails-runner