spree_static_content icon indicating copy to clipboard operation
spree_static_content copied to clipboard

Table 'myproject_development.spree_page_translations' doesn't exist

Open xu4wang opened this issue 4 years ago • 2 comments

I just installed i18n and globalize gem, please find below the statement in my Gemfile

gem 'spree_static_content', github: 'spree-contrib/spree_static_content'
gem 'spree_i18n', github: 'spree-contrib/spree_i18n'
gem 'spree_globalize', github: 'spree-contrib/spree_globalize'

The spree_static_content was added before and working as expected. However after install i18n and globalize today, the pages can not work. I get error when accessing the pages tab on /admin with below information.

`Showing /Users/wangxu/.gem/ruby/2.7.0/bundler/gems/spree_static_content-a1e066bc612d/app/views/spree/admin/pages/index.html.erb where line #28 raised:

Mysql2::Error: Table 'myproject_development.spree_page_translations' doesn't exist`

xu4wang avatar Apr 13 '20 06:04 xu4wang

From the stack trace:

.... activerecord (6.0.2.2) lib/active_record/relation/finder_methods.rb:500:in find_take' activerecord (6.0.2.2) lib/active_record/relation/finder_methods.rb:98:in take' activerecord (6.0.2.2) lib/active_record/relation/finder_methods.rb:81:in find_by' spree_static_content (a1e066bc612d) lib/spree_static_content.rb:19:in matches?' actionpack (6.0.2.2) lib/action_dispatch/routing/mapper.rb:40:in block in matches?' actionpack (6.0.2.2) lib/action_dispatch/routing/mapper.rb:39:in all?' actionpack (6.0.2.2) lib/action_dispatch/routing/mapper.rb:39:in `matches?' ....

Checked the source of lib/spree_static_content.rb,

https://github.com/spree-contrib/spree_static_content/commit/694bce534857cb4f85033a0689a9e9c0e03ec87a#diff-5627e6f87e4b5791c859c7a51762eef9

It looks like the issue was introduced by commit 694bce534857cb4f85033a0689a9e9c0e03ec87a, "Make SpreeGlobalize optional" . The SpreeGlobalize didn't create spree_page_translations.

@damianlegawiec

xu4wang avatar Apr 13 '20 07:04 xu4wang

checked the migration file of static_content gem, it did try to create the translation table.

This migration comes from spree_static_content (originally 20170827000001)

class AddTranslationToSpreePages < SpreeExtension::Migration[4.2] def up params = { title: :string, body: :text, slug: :string, foreign_link: :string, meta_keywords: :string, meta_title: :string, meta_description: :string } if defined?(SpreeGlobalize) Spree::Page.create_translation_table!(params, { migrate_data: true }) end end

def down if defined?(SpreeGlobalize) Spree::Page.drop_translation_table! migrate_data: true end end end

I understand the issue I'm facing is I install static_content gem first, and spree globalize gem later. Which makes the translation table not generated.

How shall I do? Is there a way to re-run the migration files and regenerate the translation table?

xu4wang avatar Apr 13 '20 08:04 xu4wang