# Rolling back a plugin migration

**URL:** https://meta.discourse.org/t/rolling-back-a-plugin-migration/201712
**Category:** Development
**Created:** [August 25, 2021, 6:34pm UTC](https://meta.discourse.org/t/rolling-back-a-plugin-migration/201712 "2021-08-25T18:34:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Grayden\_Shand](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grayden_shand/32/166586_2.png) [@Grayden\_Shand](https://meta.discourse.org/u/Grayden_Shand)
#### Post date: [August 25, 2021, 6:34pm UTC](https://meta.discourse.org/t/rolling-back-a-plugin-migration/201712/1 "2021-08-25T18:34:39Z")

</div>

I’m working on a plugin (my first attempt at doing so).

The plugin requires extending the database with a new migration. I was able to run this initial migration using the `bin/rake db:migrate` command.

I noticed some problems with the migration afterwards, and am trying to rollback the database, then edit and re-run the migration.

However, when I run `bin/rake db:rollback`, I’m getting the following error:

```plaintext
rake aborted!
ActiveRecord::UnknownMigrationVersionError: 

No migration with version number 20210820205029.

```

The version number in the error message does correspond with the plugin migration I’m working on.

Any ideas?

---

<div class="post-metadata">

### Author: ![markvanlan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markvanlan/32/160087_2.png) [@markvanlan](https://meta.discourse.org/u/markvanlan)
#### Post date: [August 25, 2021, 6:37pm UTC](https://meta.discourse.org/t/rolling-back-a-plugin-migration/201712/2 "2021-08-25T18:37:28Z")

</div>

Yeah, you can’t currently rollback migrations in plugin directories. The way I do it is move the migration to the core repo  
`mv plugins/discourse-example/db/migrate/20210823160357_migration.rb db/migrate/20210823160357_migration.rb`

rollback, and then move it back to the plugin  
`mv db/migrate/20210823160357_migration.rb plugins/discourse-example/db/migrate/20210823160357_migration.rb `

If your migration isn’t the last migration in the core `db` directory, you can use `bin/rails db:migrate:down VERSION=20210823160357` to target the migration you just moved.

---

<div class="post-metadata">

### Author: ![4ong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/4ong/32/186618_2.png) [@4ong](https://meta.discourse.org/u/4ong)
#### Post date: [August 27, 2021, 9:14pm UTC](https://meta.discourse.org/t/rolling-back-a-plugin-migration/201712/3 "2021-08-27T21:14:57Z")

</div>

Nice lifehack, thanks!
