Search code examples
ruby-on-railsrubysqliterakedatabase-migration

SQLite Command Line - remove migration error


I have an issue with my Rails app database which now prevents me from completing any migrations.

I've run the following on my command line with the following results -

PRAGMA table_info(events);

0|id|INTEGER|1||1
1|title|varchar|0||0
2|location|varchar|0||0
3|date|date|0||0
4|time|time|0||0
5|description|text|0||0
6|organised_by|varchar|0||0
7|created_at|datetime|1||0
8|updated_at|datetime|1||0
9|user_id|integer|0||0
10|image_file_name|varchar|0||0
11|image_content_type|varchar|0||0
12|image_file_size|integer|0||0
13|image_updated_at|datetime|0||0
14|category_id|integer|0||0
15|url|varchar|0||0
16|number_of_spaces|integer|0||0
17|price|integer|0||0
18|is_free|boolean|0||0
19|organiser_profile|url|0||0

The issue here is with No 19 on this table -

 19|organiser_profile|url|0||0

Url is not an acceptable data type which was inputted in error. I believe this is the stumbling block preventing my database from committing any further migrations.

I'm fairly new to Rails and have never manually amend a database before. What I want to do is the following -

  1. Delete / remove / dump - No 19 from my Events table. The entire line has to be gone.

  2. Check what is in the database before I perform a rake db:drop (this app is in development so there won't be much

  3. Before I perform the following action - bundle exec rake db:drop db:create db:migrate, I want to briefly understand what consequences could come from this

I'm pretty sure this is what is required to fix this issue and allow me to perform migrations again and move forward with my app. I've never done any of the above before and would be extremely grateful for any assistance on this process.


Solution

  • You're not in production yet or in danger of losing valuable information so just check out the db file from github from before the erroneous migration.

    git checkout <commit> file
    

    Then fix the migration that's erroneous then run migrations again with rake db:migrate. There's no need in this case to be trying to manually edit the table from the command line, unnecessary.