On 01/10/2012 09:41 AM, amir e. wrote:
## Hi ##
I have 6 simple and fundamental Problem in RoR migration and although I
googled it and read many article about it and research it for a week , I
didn't understand it. please help me for these problems :
----------
1 - When I create a model (for example "rails generate model
Football_League") , I see in db/migration a "create_football_leagues.rb"
. I want know what is the rules of RoR for changing the name that I gave
to my migration ? ( My migration's name was FootballLeague and ruby
cretaed "create_football_leagues.rb")
The name of the migration is only of passing interest. What it is named
has very little to do with what it does. The whole idea of the
migrations is to create/delete database tables and indexes and to
add/remove columns to existing tables and sometimes to insert small
amounts of initial data into tables (not recommended). The important
thing in the migrations is the names of the tables and the names of the
columns. The name of the migration is just so you recall what that
migration was all about.
----------
2 - What is the rules of naming ruby for creating a class in that file ?
( Ruby created a "CreateFootballLeague" class in
"create_football_leagues.rb")
As in the migration name, the name of the class that is in that file is
of little interest. It is only used when you run a migration and really
has nothing to do with what the migration really does. The class is
bound to the name of the file by some rules that are not really very
interesting. Just go with it and don't worry about it.
----------
3 - After I use rake db:migrate , although I had 3 migration, I just see
such a image in cmd : ( I attached this image )
and I didn't any migration for another 3 migrations whereas sometimes
ago when I run a migration with rake db:migrate, all my migrations are
migrated.
----------
4 - After I type rake db:migrate and after that Rake execute
"create_football_leagues.rb" I go to mysql and I saw a table with
"schema_migrations" name. and in that table there are some versions of
my migrations. now I want to know what is the application of such a
table ?
The schema_migrations table is used to keep track of which migrations
have been run. In 3 above all of the previously defined migrations have
run so the only one that will be run is the new one. If you change a
migration file which has already been run it will not be rerun. Only
the migrations on a whole are tracked. If you want to run all of the
migrations you can just 'rake db:drop db:create db:migrate'. Of course
you will loose any data that is in the database.
----------
5 - In http://guides.rubyonrails.org I read that if we want to change
the primary key of a table from default id to our own field we must use
:primary_key option but I didn't understand how can I use it .If someone
can give an example for this subject.
Don't do it. Rails works best and most easily if you go with the flow.
----------
6 - What is the difference between this 2 commands : 1 - "rails generate
migration footabll" 2 - rails generate model football. I knew that
with "rails generate model football" we must some extra file in
app/model but I don't understand function of those files.
You need to read the tutorials on models. The migration generates the
database tables. The model files define relations among the different
Active Record classes that are formed from those columns. At a minimum
a model file is required for each table (that you want to use with
Active Record). The file will look like:[code]class Column <
ActiveRecord::Base
end<[/code]The relations are descirbed in the model files.
Norm
My friend please help me to solve these fundamental problems . special
thanks .
Attachments:
http://www.ruby-forum.com/attachment/6895/1.JPG
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.