Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Issues with db:setup and db:migrate #49

Open
spockz opened this issue Feb 1, 2013 · 3 comments
Open

Issues with db:setup and db:migrate #49

spockz opened this issue Feb 1, 2013 · 3 comments

Comments

@spockz
Copy link

spockz commented Feb 1, 2013

Given an initial model Foo:

class Rekenservice
  include DataMapper::Resource  

  property :prop1,      Integer
end

We perform a rake db:setup && rake db:migrate and all is fine. Now later in development we add a new
property to our column :prop2.

class Rekenservice
  include DataMapper::Resource  

  property :prop1, Integer
  property :prop2, Integer
end

We write a migration for this that reads as follows:

migration 1, :add_prop2 do
  up do
        modify_table :foos do
            add_column :prop2, Integer
        end
    end
end

Subsequently calling rake db:migrate is no problem. However, now when we run rake db:setup && rake db:migrate again after deleting our database we get the following error:

duplicate column name: prop2

This because auto_migrate! in rake db:setup already created the column for :prop2.

What to do about this?

@c0ze
Copy link

c0ze commented Jun 2, 2017

Sorry for digging this up. Have you found a solution for this ? (other than moving away to another ORM). Currently I'm simply not running migrations for new DBs.

@spockz
Copy link
Author

spockz commented Jun 2, 2017

@c0ze I honestly don't remember and I'm no longer with the project. I suppose setup and migrate at the same time might be a bit strange.

@tpitale
Copy link
Member

tpitale commented Jun 2, 2017

Not a good idea to mix auto migration and migration files. One or the other. Also, db:setup appears to do some portion of the migration. Try db:create db:migrate if you don't want auto migration.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants