spree-contrib / spree_static_content

Manage static pages for Spree Commerce.
http://guides.spreecommerce.org
BSD 3-Clause "New" or "Revised" License
217 stars 332 forks source link

Table 'myproject_development.spree_page_translations' doesn't exist #274

Open xu4wang opened 4 years ago

xu4wang commented 4 years ago

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 commented 4 years ago

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:intake' 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:inmatches?' 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:inall?' 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 commented 4 years ago

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?