Forum: Ruby on Rails migration issue

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-05-27 16:34
I was following this set of instructions from the "Cookie overflow?"
thread:

> Your sessions (by default in cookie) needs to be moved to Active record
> store or memcache store to fix this issue.
>
> For Databased sessions:
> config.action_controller.session_store = :active_record_store
> You need to create the session table as below
> rake db:sessions:create
> rake db:migrate

I added the config line to environment.rb; is that the approriate place?

When I ran the migration, I got

rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "artists" already exists: [etc]

So I removed the existing, populated database (to a safe place, since I
do not want to have to create it again unless necessary) and ran the
rake db:migrate again...clearly there is something I don't understand
because most sane people would want to preserve the contents of an
existing db when they modify it.

Now I have a problem, because of course the new (empty) database has an
extra table in it.  Before I go and write a ruby script to create a
database containing my old records + the new table as it appears in
schema.rb, is there not a simpler, more sensible way to do this?

If I do have to remake the db manually, can anyone answer a questions
for me regarding the session table: Does it also use a column "id" as
the INTEGER PRIMARY KEY?  I suppose it won't matter if it doesn't and I
put one in anyway...
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2009-05-27 20:56
(Received via mailing list)
On Wed, May 27, 2009 at 7:34 AM, Mk 27
<rails-mailing-list@andreas-s.net> wrote:

> because most sane people would want to preserve the contents of an
> existing db when they modify it.

Erm, so maybe the most appropriate ("sane") thing to do at that
point would be to figure out *why* you're (apparently) repeating a
migration that's already been done?

Just sayin' ... :-)
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-05-27 23:03
(Received via mailing list)
This would suggest that the migration you were running was attempting to
add
the artists table.  I think this is nothing to do with rake
db:sessions:create.  Have a look in the migration made by the rake to
see
what it is doing.  I imagine that you have an earlier migration that
created
the artists table and for some reason that is running again.

Colin

2009/5/27 Mk 27 <rails-mailing-list@andreas-s.net>
Ced56202e9039027cfc2da2f70457977?d=identicon&s=25 E. Litwin (Guest)
on 2009-05-27 23:34
(Received via mailing list)
And check the schema_migrations table in the database. Maybe an older
database was restored from a backup for some reason.
Ced56202e9039027cfc2da2f70457977?d=identicon&s=25 E. Litwin (Guest)
on 2009-05-27 23:38
(Received via mailing list)
Also, check the schema_migrations table in your database to see what
migration it thinks you last ran.
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-05-28 00:35
Hassan Schroeder wrote:
> On Wed, May 27, 2009 at 7:34 AM, Mk 27
> <rails-mailing-list@andreas-s.net> wrote:
>
>> because most sane people would want to preserve the contents of an
>> existing db when they modify it.
>
> Erm, so maybe the most appropriate ("sane") thing to do at that
> point would be to figure out *why* you're (apparently) repeating a
> migration that's already been done?

There was an existing database, yes, I thought that was clear.  The
reason I did it again was (also clear if you can read, but to repeat)
because I wanted to move the session store to Active Record so I was
following this instruction:

> You need to create the session table as below
> rake db:sessions:create
> rake db:migrate

Which I am grateful for that advice, because it worked; but I did have
to create the db manually (because I want it populated, and already have
a script to do that), add the session table myself (to the
aforementioned script), and insert it back in.  So I guess I don't get
the point of the migration thing yet:  is it more for people who don't
want to create a db themself, or what?

Nb, this is my second casual week using rails.  If all I want to do is
add a table to the database, why would it want to rebuild the whole
thing, ie, why not just add the new table and leave the existing tables
alone?  I presume there is away to do this and I haven't read enough of
the API docs yet.  Is this going against "the convention", hence I
needed to do some more "configuration"?
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2009-05-28 01:02
(Received via mailing list)
On Wed, May 27, 2009 at 3:35 PM, Mk 27
<rails-mailing-list@andreas-s.net> wrote:

> There was an existing database, yes, I thought that was clear.  The
> reason I did it again was

Yes, yes, entirely clear, and totally irrelevant to the issue.

> Which I am grateful for that advice, because it worked; but I did have
> to create the db manually (because I want it populated, and already have
> a script to do that), add the session table myself (to the
> aforementioned script), and insert it back in.

No, you didn't - that's the whole point  :-)

> So I guess I don't get the point of the migration thing yet:

Apparently -- so, seriously, read up on migrations before you go any
further. You'll save yourself a lot of headaches down the road.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
68814ed988eee4f21b2cd07353e5e445?d=identicon&s=25 Mk 27 (mk27)
on 2009-05-28 01:03
Hassan Schroeder wrote:

> nothing of interest to me either

Thanks for your non-advice!

;)
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2009-05-28 01:07
(Received via mailing list)
On Wed, May 27, 2009 at 4:03 PM, Mk 27
<rails-mailing-list@andreas-s.net> wrote:

>> nothing of interest to me either
>
> Thanks for your non-advice!

Where did I say that? Must be some cross-talk in your mail client :-)

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-05-28 06:04
Mk 27 wrote:
> Hassan Schroeder wrote:
>
>> nothing of interest to me either
>
> Thanks for your non-advice!
>
> ;)

Hassan gave you some excellent advice.  Read it again -- and this time,
if you want to learn, I suggest that you ask instead of hurling insults.
(I also suggest that an apology to Hassan might be in order, but that's
between you and him.)

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-05-28 22:54
(Received via mailing list)
2009/5/27 Mk 27 <rails-mailing-list@andreas-s.net>

> > migration that's already been done?
> Which I am grateful for that advice, because it worked; but I did have
> the API docs yet.
You have hit the nail on the head here, that is exactly what migrations
will
do for you (ie "add the new table and leave the existing tables alone")
in
addition to other things of course.

Colin
This topic is locked and can not be replied to.