I've defined a scaffold with some of the sqlite columns having type double. When I run rake db:migrate, it gives the following error:
undefined method `double' for #<ActiveRecord::ConnectionAdapters::TableDefinition:>
Is there another way to specify a double that Rails will understand? Should I be using a float here?
Here's the scaffold command:
rails generate scaffold shop name:string latitude:double
Try using float instead of double. Take a look here.
Related
When I run rake db:migrate, show the following error:
-- create_table(:posts)<br>
rake aborted!
StandardError: An error has occurred, all later migrations canceled:`<br>
undefined method 'int' for #
<ActiveRecord::ConnectionAdapters::MySQL::TableDefinition:0x0055c088b9f520>
Did you mean? in?
Any ideas or suggestions?
I just change the migrate file in db/migrate from int to integer. Like this: t.integer: age
A reason this could happen is if you accidentally got a column name and a data type around the wrong way during rails generate model ....
For example, if you accidentally ran rails g model calculations references:appointment (instead of rails g model calculations appointment:references), then you'd have:
t.appointment :references
but it should be
t.references :appointment
The same mistake could happen with not just references, but any other data type too (e.g. integer, string and so on).
I'm getting this error message when I run the above code generator: (I'm just a beginner)
invoke active_record
Another migration is already named create_posts.....
Use --force to remove the old migration file
What do I type into the terminal window to "use force"
You are getting the following error because you already have a migration named create_posts in your rails application.
invoke active_record Another migration is already named create_posts..... Use --force to remove the old migration file
So, what you need here is first remove the existing migration and then generate the scaffold.
rails d migration create_posts
rails generate scaffold post title:string body:text
Or
You could generate the scaffold using --force option
rails generate scaffold post title:string body:text --force
EDIT
As per your comment:
I did that and then a whole bunch of code appears with the lines of
code sating invoke...exist...identical.
It means that you already ran a scaffold once for Post successfully and you are trying to generate the scaffold again.
I am not sure why you are doing that BUT identical is not an error. Its just that Rails is telling you that you already have a particular file so I am not creating again.
You can reset your database if you don't care about losing your database with this :
b rake db:reset
This will re-reun all your migrations. But take note! Your migrations should be able to run from one end to the other. So if something is "not working" with the regular rake db:migrate, then you should resolve that issue is specifically.
Show me a more descriptive error, and I can tell you more.
You should add other migration in order to change your Post table as you want it to be.
Your could begin with rails g migration and see the help provided.
If you want to get away with it you can delete the migration that created the Post table (but I guess you would need to delete the DB)
After the first time you generate a scaffold, by default Rails will not overwrite the existing scaffold. This is to ensure that you don't accidentally destroy a lot of work.
If you're really sure you want to regenerate the scaffold and delete any changes you might have made to any of the generated files, try:
rails generate scaffold post title:string body:text --force
I'm trying to create a simple application with Ruby on Rails. I've created this scaffold:
rails generate scaffold Pic title:string content:blob description:text
and when I try to migrate db with rake db:migrate I'm getting this error:
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `blob' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0xb74f8ec4>
When I write say text instead of blob it works normally. So what's the problem with blob ?
The keyword is binary, not blob.
rails generate scaffold Pic title:string content:binary description:text
There is no keyword blob in rails, you need binary.
rails generate scaffold Pic title:string content:binary description:text
I am doing the following tutorial, to learn how to use dhtml in rails.
http://www.dhtmlx.com/blog/?p=426
I reach the point where I create the migration however when I do the rake db:migrate I recieve the following error:
An error has occurred, this and all later migrations canceled:
uninitialized constant CreateUsers::User
Don't seem to understand how I can possibly be recieving this error especially by simply following a tutorial. "/
Make sure you generate the User model before running the migration. (ruby script/generate model user in the tutorial, but rails g model User for Rails 3)
EDIT: As Jeremy pointed out, generating the model will create a migration file for you. The tutorial shows things in a somewhat backwards order.
I'm trying to create a new model like this:
rails generate model Tags name:string
When I run this, I get the following error:
base.rb:266:in `const_defined?': wrong constant name tags (NameError)
Any thoughts? I tried changing Tags to ReportTags and it still gave me the same error.
Model names are singular - try
rails generate model Tag name:string