Project

General

Profile

Migration - ActiveRecord::UnknownPrimaryKey: Unknown primary key for table roles in model Role.

Added by György Varga about 1 year ago

Hi All,
I tried to use old database with new installation. I tried to migrate database:


bundle exec rake db:migrate RAILS_ENV=production 

== 20170418090031 AddViewNewsToAllExistingRoles: migrating ====================
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

can't write unknown attribute ``

          raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{name}`" 
          ^^^^^
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/attribute.rb:207:in `with_value_from_database'
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/attribute_set.rb:51:in `write_from_user'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:415:in `restore_transaction_record_state'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:334:in `rolledback!'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:134:in `rollback_records'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:312:in `block in rollback_transaction'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:309:in `rollback_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:325:in `rescue in block in within_new_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:322:in `block in within_new_transaction'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:302:in `save!'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/suppressor.rb:48:in `save!'
/usr/share/redmine/app/models/role.rb:134:in `add_permission!'
/usr/share/redmine/db/migrate/20170418090031_add_view_news_to_all_existing_roles.rb:3:in `block in up'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/relation/delegation.rb:88:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/relation/delegation.rb:88:in `each'
/usr/share/redmine/db/migrate/20170418090031_add_view_news_to_all_existing_roles.rb:3:in `up'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:870:in `public_send'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:870:in `exec_migration'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:850:in `block in migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:849:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1037:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1382:in `ddl_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1302:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1251:in `block in migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1251:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1086:in `up'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1061:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/railties/databases.rake:90:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'

Caused by:
ActiveModel::MissingAttributeError: can't write unknown attribute ``

          raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{name}`" 
          ^^^^^
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/attribute.rb:207:in `with_value_from_database'
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/attribute_set.rb:51:in `write_from_user'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:415:in `restore_transaction_record_state'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:334:in `rolledback!'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:134:in `rollback_records'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:312:in `block in rollback_transaction'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:309:in `rollback_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:325:in `rescue in block in within_new_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:322:in `block in within_new_transaction'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:302:in `save!'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/suppressor.rb:48:in `save!'
/usr/share/redmine/app/models/role.rb:134:in `add_permission!'
/usr/share/redmine/db/migrate/20170418090031_add_view_news_to_all_existing_roles.rb:3:in `block in up'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/relation/delegation.rb:88:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/relation/delegation.rb:88:in `each'
/usr/share/redmine/db/migrate/20170418090031_add_view_news_to_all_existing_roles.rb:3:in `up'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:870:in `public_send'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:870:in `exec_migration'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:850:in `block in migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:849:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1037:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1382:in `ddl_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1302:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1251:in `block in migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1251:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1086:in `up'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1061:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/railties/databases.rake:90:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'

Caused by:
ActiveRecord::UnknownPrimaryKey: Unknown primary key for table roles in model Role.
Cannot validate uniqueness for persisted record without primary key.
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/validations/uniqueness.rb:28:in `validate_each'
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/validator.rb:153:in `block in validate'
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/validator.rb:149:in `each'
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/validator.rb:149:in `validate'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:427:in `block in make_lambda'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:604:in `block (2 levels) in default_terminator'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:603:in `catch'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:603:in `block in default_terminator'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:199:in `block in halting'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:512:in `block in invoke_before'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:512:in `each'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:512:in `invoke_before'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:105:in `run_callbacks'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:824:in `_run_validate_callbacks'
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/validations.rb:406:in `run_validations!'
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/validations/callbacks.rb:117:in `block in run_validations!'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:106:in `run_callbacks'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/callbacks.rb:824:in `_run_validation_callbacks'
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/validations/callbacks.rb:117:in `run_validations!'
/usr/share/rubygems-integration/all/gems/activemodel-6.1.7.3/lib/active_model/validations.rb:337:in `valid?'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/validations.rb:68:in `valid?'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/validations.rb:84:in `perform_validations'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/validations.rb:53:in `save!'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:302:in `block in save!'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:354:in `block in with_transaction_returning_status'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/usr/share/rubygems-integration/all/gems/activesupport-6.1.7.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/transactions.rb:302:in `save!'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/suppressor.rb:48:in `save!'
/usr/share/redmine/app/models/role.rb:134:in `add_permission!'
/usr/share/redmine/db/migrate/20170418090031_add_view_news_to_all_existing_roles.rb:3:in `block in up'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/relation/delegation.rb:88:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/relation/delegation.rb:88:in `each'
/usr/share/redmine/db/migrate/20170418090031_add_view_news_to_all_existing_roles.rb:3:in `up'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:870:in `public_send'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:870:in `exec_migration'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:850:in `block in migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:849:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1037:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1382:in `ddl_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1302:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1251:in `block in migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1251:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1086:in `up'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/migration.rb:1061:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <top (required)>'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/railties/databases.rake:90:in `each'
/usr/share/rubygems-integration/all/gems/activerecord-6.1.7.3/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

I could not find any information about it.
Note: the old database was dumped by mysql, the new server is MariaDB, therefore I used an on-line converter. The database looks as correct, I can browse it from my computer remotely.
Do you have any idea? How to migrate it?


Replies (2)

RE: Migration - ActiveRecord::UnknownPrimaryKey: Unknown primary key for table roles in model Role. - Added by Holger Just about 1 year ago

When you transferred your database from MySQL to MariaDB, it appears that information about the primary key of (at least) the roles table went missing. That's the likely cause of the error you receive:

ActiveRecord::UnknownPrimaryKey: Unknown primary key for table roles in model Role.
Cannot validate uniqueness for persisted record without primary key.

Make sure that the primary key definitions of all tables are the same as in your MySQL database. Generally, the primary key isthe id column in all tables which have such a column (i.e. all tables apart from some many-to-many join tables).

RE: Migration - ActiveRecord::UnknownPrimaryKey: Unknown primary key for table roles in model Role. - Added by György Varga about 1 year ago

Thank you for your prompt answer. Unfortunately, I cannot check MySql database because I have lost my old server and now, I have MariaDB only in the new one. I have backup dump only. Do you have any idea, how to convert it correctly? I could not find a simple solution and I'm not an expert in databases. I'm only a simple user. Or can you public a link to the step-by-step instruction? It could help me.

    (1-2/2)