Getting error while running migration command [closed] - ruby-on-rails

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
The message I'm getting after running migration command
The db file created after runnig above command is as below
[enter image description here][2]
Error I'm getting while trying to connect with table(demo) in database demo:

let me explain about your error message and your understanding above, when you typed rails generate migration demo (this is from your picture) and then the command line showing the file created, it does not meant the db file created, rails generate migration command usually to add/remove fields from existing table, it's just empty file that that you should put some additional command inside, check db/migration folder,
I believe this getting started with rails can help you.
basically for database steps
Create database file first with rake db:create
create your model with rails generate model Demo, again file created but you have to put some fields inside, check db/migration folder after you run this command
after you put fields then run rake db:migrate
if you missed some fields then you can add additional fields with rails generate migration AddDateToDemo
then put some fields inside and then run rake db:migrate, it's script for rails to execute job database creation/add/remove fields

Related

Change Ruby on Rails scaffolding order [duplicate]

This question already has an answer here:
Hartl's rails tutorial completed works locally perfect. Heroku persists "We're sorry, but something went wrong."
(1 answer)
Closed 6 years ago.
I have a Ruby on Rails app and I want to deploy it on Heroku. Some errors appear and I think it is because the scaffolding order.
By that, I mean that a class named submissions is first created, but this class references another class named Users that is yet to be created.
This is the error that appears when doing rake db:migrate http://pastebin.com/R83a3rsN
And those are the migrate files and their filename
I guess you mean that:
http://pastebin.com/ig5nHjsj for 20160503205437_create_submissions
and
http://pastebin.com/q2jABiep for 20160428101834_create_users
You have a member in your db/migrate folder named...
20160424205437_create_submissions.db
Just rename it to
20160503205437_create_submissions.db
that will move it to the bottom of the list of migrations and it'll be executed last.
This doesn't seem like a scaffold error per se. Rather, it's an issue with migrations (which scaffolds happened to generate).
To repairs the issue, I'd probably just make a fresh migration which includes all columns your application needs at this point in time. Then edit the order of the create_table blocks to resolve your error.
Then you'd be able to delete the other migration files and run dB:create or reset.
This is an issue with cross-dependencies in your migration. In this case, the Submissions table is expecting that the Users table already exist in order to declare a foreign key to it.
Consider declaring the Users table above the Submissions table in your migration.

Ruby on Rails 4 adding CRUD [duplicate]

This question already has answers here:
Rails: How to run `rails generate scaffold` when the model already exists?
(7 answers)
Closed 7 years ago.
This is my current situation:
ShoeDeal/
app/controller/
shoe_controller.rb
app/model/
customer.rb
item.rb
order.rb
app/views/shoe/
index.html.erb
db/migrate/
create_customers.rb
create_items.rb
create_orders.rb
I’m making a simple ShoeDeals App where your can select a pair of shoes that you want to purchase and add to a shopping cart. i just kinda found out that ruby has a CRUD terminal command ( rails generate scaffold ) but i already started manually creating the files list. Can i still run this code to finish where i left off?
Generating scaffold files for an existing model/controller etc will create the standard files where they don't exists and skip the ones that do. You can temporarily rename your existing files and inspect/merge the generated code into your existing classes.

Is it possible to download a database from Sublime Text 3? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm following Michael Hartl's RoR Tutorial and in Lesson 6 he opens the database using the Cloud 9 IDE. I'm using Sublime Text 3 and I can't figure out how to download the development.sqlite3 file. Is it possible to download a database file and open it Sublime Text 3?
You can try to manually load the sqlite3 module (instructions for MacOS)
Copy the entire sqlite3 folder from
/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3
to your Sublime Text 3 folder
Then copy
/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload
To the same folder
finally on Sublime click View -> Show Console and then type
import sqlite3
If you're working in a Rails project using SQLite, the development.sqlite3 file should already be generated in the db directory within your project - there's no need to download it.
Opening the file itself in Sublime would probably not be very useful to you as it's going to be a huge series of unreadable characters representing the db. If you want to interface with the data within your db, here are some options:
rails dbconsole - this command figures out which database you're using and drops you into whichever command line interface you would use with it. Once you're in the CLI, you can perform SQLite commands, such as getting lists of records from tables, making changes to data, etc. - more info
rails console - assuming you have the proper models and database adapters configured, you can always drop into the Rails console - rails c - and use ActiveRecord to make some basic calls to the database. - more info
SQLite GUIs - there are many applications out there that provide a nice tabular user interface to interact with the data in your db. Some cross-platform examples for SQLite are:
SQLite Studio - http://sqlitestudio.pl/
SQLite Browser - http://sqlitebrowser.org/
Hope this helps!

Syntax error and db.migrate error preventing me from moving forward [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
https://github.com/justuseapen/omrails
Link to the repo^
When I run the app on my local server I get a syntax error in the browser. Apparently something wrong with the <%= end %> in my application.html.erb file.
I followed the onemonthrails tut as exactly as possible, excluding the heroku pushes because I cannot for the life of me get my ssh keys to line up (that's for another question).
Also, when I run rake db:migrate (or bundle exec db.migrate) I get an error that says
don't know how to build task db.migrate
Any suggestions on a fix? I already check this question: Don't know how to build task 'db:migrate' w/ Rails 3.2.0.rc2
and found no relevant solution but perhaps I'm missing something.
Without knowing more specifics, it might be that <%= end %> should be written as <% end %> (no =) is the trouble with your application.html.erb
Also, bundle exec db.migrate should be bundle exec db:migrate (: rather than .)

Is it a good idea to put db/schema.rb to .gitignore list ?? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
so what I'm suggesting in my job, is to put db/schema.rb into .gitignore file, so we don't have (time to time) merging problems.
There are some concerns that if something terrible happen (meteor fall from the sky right on the DB server and simultaneously all the db/migrete files are corrupt) we could loose the schema, and we will have to use rake db:purge (to reuse the schema.rb). I agree that this is possible and it's a good argument, but it shouldn't be problem because db/schema.rb is generated each time we do rake db:migrate. So even if we won't push schema.rb on server, we are pushing migrations add running db:migrate each time we are deploying with DB changes and with that db:migrate rails will automatically generate schema.rb on server side, and that schema.rb sits on the server unchanged until we do another db:migrate .
so whats your opinion, should we or should we not put the db/schema.rb into git ignore ?
thank you
I would always suggest to keep schema.rb in version contol, since tasks like rake db:schema:load depend on it being there.
About the conflicts, are you talking about the schema version conflicts? These are easily mitigated using the merge algorithm showed here: http://tbaggery.com/2010/10/24/reduce-your-rails-schema-conflicts.html
Other conflicts, like column definition switching locations can easily be avoided by being careful what you commit to the repository.
You should put in a VCS whatever you need to reproduce an operational environment.
If, for rebuilding your application, you need to have the right schema.rb (at the right version), then yes, it can be versionned.
But if you can get it back through another process, then it is better backed up through some other referential than a VCS.
When you switch between feature branches which develop different set of model attributes, then without schema.rb you sometimes would need to:
rake db:migrate:down VERSION=xxx migrations which were create some time ago, but not merged to other branches
git checkout branch
rake db:migrate migrate all newly created branches
I run into some problems with this in previous projects where schema.rb was in .gitignore. Every time I see something was wrong, I had to drop database and recreate from migrations, while with schema.rb I could just load schema in fraction of second and then rake db:seed to load data. But it wasn't critical.
I'm also curious what problems you have with merging schema.rb? Most of the time you can override this file without worrying about changes (I assume you haven't modified your database structure by hand) with rake db:dump and just add it as merge resolution.

Resources