Getting an error on adding migration

Hello ,

I am a ROR beginner. I did scaffolding and made a table called
register with a field “name”. Now when I tried to add one more column
using add migration and then rake db:migrate, the command is executing
successfully but new columns are not coming in the table

Sam

Sam John wrote:

Hello ,

I am a ROR beginner. I did scaffolding and made a table called
register with a field “name”. Now when I tried to add one more column
using add migration and then rake db:migrate, the command is executing
successfully but new columns are not coming in the table

Sam

can u plz brief a lil bit more than i am able to understand …that y ur
columns are not coming in the table

Sara Criss wrote:

Sam John wrote:

Hello ,

I am a ROR beginner. I did scaffolding and made a table called
register with a field “name”. Now when I tried to add one more column
using add migration and then rake db:migrate, the command is executing
successfully but new columns are not coming in the table

Sam

can u plz brief a lil bit more than i am able to understand …that y ur
columns are not coming in the table

Thank you for the reply :slight_smile: . I will explain . I did scaffolding and
made a table called register with a field “name” . After that as I
wanted to add more fields in that table I did the add migration command
which is “ruby script/generate migration AddPasswordToRegister
password:varchar” and also the rake db:migrate command. But when I run
it on the browser the new column (password) which has been added is not
showing there. it is only showing the “name” field which i got when i
did scaffolding. I am able to add many columns through migration but
they are not displaying on the browser. When I checked the files in my
system , I could find out that new migration files are being created in
the db/migration folder but nothing is being created in the views.

hope this would help you to understand my problem now

Sam

Sam Migration is to database and Scaffold is for view purpose.

On running migration a column may be added to yr DB. Check that first if
there is a column the work of migration is that and its done.

Scaffold is responsible to generate CRUD skeleton code. Since you did
scaffold before adding the new field password thats not reflected.

Cheers,
Ratnvael.

Enabling Migrations

It’s time to make some more changes to our model.

Let’s introduce a Url property to the Blog class.
public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
public string Url { get; set; }
}
If you were to run the application again you would get an
InvalidOperationException because the database no longer matches your
model.

”The model backing the ‘BlogContext’ context has changed since the
database was created. Consider using Code First Migrations to update the
database (Code First Migrations - EF6 | Microsoft Learn).”
.
As the exception suggests, it’s time to start using Code First
Migrations. The first step is to enable migrations for our context.
Run the ‘Enable-Migrations’ command in Package Manager Console.
. .
This command has added a Migrations folder to our project. This new
folder contains two files:
The Configuration class. This class allows you to configure how
Migrations behaves for your context. For this walkthrough we will just
use the default configuration.
Because there is just a single Code First context in your project,
Enable-Migrations has automatically filled in the context type that this
configuration applies to.
An InitialCreate migration. This migration was generated because we
already had Code First create a database for us, before we enabled
migrations. The code in this scaffolded migration represents the objects
that have already been created in the database. In our case that is the
Blog table with a BlogId and Name columns.
Primavera Training in Chennai | Best Primavera Training Institutes in Chennai
Big Data Analytics Training in Chennai, sholinganallur | Best Big Data Training in OMR, Chennai