-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
Rails 4.2 Can't save data ActiveRecord::StatementInvalid: Mysql2::Error: Field 'name' doesn't have a default value #429
Comments
This error doesn't allow me to upgrade to Rails 4.2. Tried with globalize 5.0.0 and 4.0.3 same problem |
I don't know why, but in lib/patches/active_record/persistence.rb:16 selected non-translation fields only. This operation causes an error as above. |
I apologize for the mistake. Even without this rejection record is not saved and the value is lost in the depths of activerecord and activesupport gems. |
Is anybody live there? |
sure @xsrgx |
Yes, ofc. |
@simi Here is a minimal repro script which passes with |
Due to globalize/globalize#429 Dependencies will be locked until that issue is resolved.
I just ran into this issue today. Found that if a translated column has This works:
And this works:
But this gives the error:
To work around this for now I just added the |
Official advice is to remove the column from your source table completely as it no longer makes sense to have it there. |
@parndt I am having exactly the same issue that @Nike0 has after upgrading from (rails 4.1.7, activerecord 4.1.7, globalize 4.0.3) to (rails 4.2.4, activerecord 4.2.4, globalize-5.0.1). I did some tracing with byebug and the code in line 17-19 of globalize/lib/patches/active_record/persistence.rb (https://github.com/globalize/globalize/blob/master/lib/patches/active_record/persistence.rb):
seems to filter out attributes that are 'translated' (i.e., the :name field in @Nike0 and my cases) before passing them into the insert statement, thus it results in the error 'Field 'name' doesn't have a default value'. I am willing to spend more time to debug/trace this, please help guide me. Thank you. Also when you mention that the official advice is to remove the column, are you referring to :name column? If so please kindly help me understand why; the :name column in this case belongs to the table, e.g., Product#name, or is :name a reserved keyword for globalize? Thanks! |
After byebug-ing around, and re-reading the docs, I understand what @parndt meant when he said 'the official advice is to remove the column'. In globalize ~> 5.0.0, the original table must NOT have columns, e.g., in my case, the Property table has a :name column, which are to be translated since those columns should exist only in the translated table. Previously in globalize ~> 4.0.0, the columns to be translated exists in both the original table and the translated table. |
Closing this, as noted Globalize does not support having the same column on both the model table and its translation table. We may look into handling this more gracefully, but it is not the expected situation and is thus not supported in general. |
Hi, |
@kapilsdv Sorry, really nothing we can do. We're not going to chase after AR changes which conflict with this configuration since it's inherently problematic. If you upgrade to Rails/AR 5 you should be okay since we use |
Thanks for quick reply. |
Globalize will use |
@shioyama i have set |
@sachin87 you don't need to set |
@sachin87 Also, do not set |
@shioyama what should i do then, i have set |
@sachin87 Do you see the deprecation error? Are you using Rails 5? If you are using Rails 5 and see the deprecation error, but you need something in the column on every record to satisfy a |
@shioyama I have added a foreign key constraint on that column, and i already have a lot of data, i can't remove this column. |
Hi,
I have a trouble when upgrading my app from Rails 3.2.21 to 4.2.0. I can't save data in models with translates option. Here is the model example:
And Gemfile (necessary gems only):
Then I've tried to create a record:
I saw next SQL query in the log:
Then I created a new empty Rails 4.2 project. Here is all code:
Migrations:
Gemfile:
Attempt to create a record with backtrace:
Also I tried to use 4.x version of globalize and saw error like here.
Thank you.
The text was updated successfully, but these errors were encountered: