1

I am trying to change the data type of a column :price in my :products table from :float to :integer but I keep getting these errors. I have tried everything and am so stuck I thought I would finally ask for help.

Here is my database migration file code:

class ChangeDataTypeForProductPrice < ActiveRecord::Migration[5.1]
  def change
    change_column :products, :price, :integer
  end
end

Thank you to anyone in advance that can help me :)

And here is the output

Computers-MacBook-Pro:rubyapp MyComputer$ rails db:migrate
== 20180118162844 ChangeDataTypeForProductPrice: migrating ====================
-- change_column(:products, :price, :integer)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "products"
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:108:in `step'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:108:in `block in each'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:107:in `loop'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:107:in `each'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:152:in `map'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:152:in `block in execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:95:in `prepare'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:137:in `execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:251:in `block (2 levels) in execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:250:in `block in execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:249:in `execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:471:in `drop_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:435:in `move_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:427:in `block in alter_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:233:in `transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:426:in `alter_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:376:in `change_column'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/db/migrate/20180118162844_change_data_type_for_product_price.rb:3:in `change'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `block in ddl_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/transactions.rb:210:in `transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `ddl_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1150:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command.rb:46:in `invoke'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/rails:9:in `require'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/rails:9:in `<top (required)>'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/spring:15:in `require'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
ActiveRecord::InvalidForeignKey: SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "products"
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:108:in `step'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:108:in `block in each'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:107:in `loop'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:107:in `each'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:152:in `map'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:152:in `block in execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:95:in `prepare'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:137:in `execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:251:in `block (2 levels) in execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:250:in `block in execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:249:in `execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:471:in `drop_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:435:in `move_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:427:in `block in alter_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:233:in `transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:426:in `alter_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:376:in `change_column'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/db/migrate/20180118162844_change_data_type_for_product_price.rb:3:in `change'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `block in ddl_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/transactions.rb:210:in `transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `ddl_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1150:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command.rb:46:in `invoke'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/rails:9:in `require'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/rails:9:in `<top (required)>'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/spring:15:in `require'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
SQLite3::ConstraintException: FOREIGN KEY constraint failed
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:108:in `step'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:108:in `block in each'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:107:in `loop'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:107:in `each'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:152:in `map'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:152:in `block in execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:95:in `prepare'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:137:in `execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:251:in `block (2 levels) in execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:250:in `block in execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:249:in `execute'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:471:in `drop_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:435:in `move_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:427:in `block in alter_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:233:in `transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:426:in `alter_table'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:376:in `change_column'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/db/migrate/20180118162844_change_data_type_for_product_price.rb:3:in `change'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `block in ddl_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/transactions.rb:210:in `transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `ddl_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1150:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command.rb:46:in `invoke'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/rails:9:in `require'
/Users/MyComputer/Documents/Career Foundry/Achievement 3 - Basic Rails Web App/rubyapp/bin/rails:9:in `<top (required)>'
/Users/MyComputer/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'

5 Answers 5

1

According to the SQLite docs at: https://www.sqlite.org/lang_altertable.html the only actions that can alter a table are to rename and add a column. Everything else (including altering a column in this case) requires a transaction that creates a new table and drops the old.

In this case, you are not able to drop the table, since you have another table with a foreign key constraint onto the table you are trying to drop.

One approach is to add a new column with the desired type, and do a full update on the whole table to copy the float to the integer column, then make the appropriate changes to your code. Or assuming this is development delete the data that is dependent on your product table and try the migration again.

Sign up to request clarification or add additional context in comments.

5 Comments

Hey Phil! Thanks so much for the reply. I don't care about the data, it is all test data anyways. So if I understand correctly, if I delete all of the data in the price column, then it will let me do the migration? Is there an easy way to do that? Thank you so much again.
My guess is that you have a model that is related through a Rails association to this table. For example, a model / table orders could have a column product_id that could be referring to this table. You would need to go to rails db in the console then, delete from sales; to empty the sales table.
Did this work for you? Let me know and I can update my answer as necessary.
Hey Phil - I actually just reset my database and lo and behold it works now. UGH. Thanks for your help!
That would make sense if the db was rebuilt with your new migrations, and empty data.
0

You can create a new colunm and update it with the price columns data and later you could drop the old column and rename the new column as price. As a saefty precaution you can cast the float values to integer and update the newly created column.

Comments

0

You could simply create a migration to delete column :products, then create a new migration to create the column from scratch as an integer type.

Comments

0

Try to the following

rails g migration change_float_to_integer

then project/db/migrate/TIMESTAMP_change_float_to_integer.rb

Edit like below

class ChangeFloatToInteger< ActiveRecord::Migration[5.0]
    def change
        remove_column :products, :price

        add_column :products, :price, :integer
    end
end

then

rake db:migrate

Hope to help

Comments

0

ran db:reset and then all of a sudden everything works. Ugh. I guess the database was getting held up on something.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.