Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not dump due to undefined method column_spec_for_primary_key #34

Closed
memoht opened this issue Jun 16, 2018 · 8 comments · Fixed by 7even/active_record-annotate#9
Closed

Comments

@memoht
Copy link

memoht commented Jun 16, 2018

Recently finished an upgrade to Rails 5.2 for my app and used rake db:migrate:squash to cleanup previous migrations. No error message on CLI, but the create_schema.rb file is full of the following:

class CreateSchema < ActiveRecord::Migration
  def change
    # Could not dump table "accounts" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
  
  # Could not dump table "act_tickets" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
  
  # Could not dump table "active_storage_attachments" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
  
  # Could not dump table "active_storage_blobs" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>

  # Could not dump table "articles" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
  
  # Could not dump table "companies" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
  
  # Could not dump table "documents" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
  
  # Could not dump table "manifests" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
 
  # Could not dump table "notes" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>

  # Could not dump table "products" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
 
  # Could not dump table "tasks" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
  
  # Could not dump table "transfers" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
  
  # Could not dump table "users" because of following NoMethodError
  #   undefined method `column_spec_for_primary_key' for #<MigrationData::ActiveRecord::SchemaDumper:0x00007feb6b5b84f8>
  
    add_foreign_key "accounts", "companies"
    add_foreign_key "act_tickets", "companies"
    add_foreign_key "act_tickets", "users"
    add_foreign_key "transfers", "companies"
  end
end

So not sure what is wrong. Tried to pull the gem from the master branch and still same result.

@memoht
Copy link
Author

memoht commented Jun 16, 2018

Quick search reveals similar error message for another gem. Here is a link to the fix for that gem in case it provides insight.Ankane/Multiverse

@memoht
Copy link
Author

memoht commented Jun 16, 2018

I also looked through the changes made to ActiveRecord in 5.2 and this seems relevant: Remove deprecated #migration_keys.

@mapreal19
Copy link
Contributor

getting this too in 5.2

@ka8725 any ideas?

@memoht
Copy link
Author

memoht commented Oct 11, 2018

@mapreal19 @ka8725
I ended up changing line 5 of migration_data/lib/migration_data/active_record/schema_dumper.rb from:

new(connection, generate_options(config)).dump(stream)

to

connection.create_schema_dumper(generate_options(config)).dump(stream)

and was then able to run the squash command. The result didn't error out but I had to remove a few lines as it appeared to dump a single migration file. So a work-around, but not perfect.

@mapreal19
Copy link
Contributor

@memoht maybe we can sanitize that output removing those lines? I had to do the same thing myself

westonganger added a commit to westonganger/active_record-annotate that referenced this issue Dec 27, 2018
westonganger added a commit to westonganger/active_record-annotate that referenced this issue Dec 27, 2018
@mapreal19
Copy link
Contributor

Another idea could be to use https://github.com/jalkoby/squasher, the focus of this gem could just be data migrations and testing them

@memoht
Copy link
Author

memoht commented Jan 23, 2019

@mapreal19 Thanks for the recommendation.

@ka8725
Copy link
Owner

ka8725 commented Jan 27, 2020

Have just released the new version and it doesn't have squasher anymore. Thanks for your contribution, guys!

@ka8725 ka8725 closed this as completed Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants