You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using mariadb 10.3.0 version with Rails 5.1.4 with this setup
The 'json' datatype is not recognised by activerecord mysql2 when used in migration file like this
create_table :posts do |t|
t.column :title_translations, 'json'
t.timestamps
end
Error:
Caused by:
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json NOT NULL,
The text was updated successfully, but these errors were encountered:
I was able to make a column by using this way inside migration class
def up
execute <<-SQL
CREATE TABLE categories(
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
name_translations TEXT NOT NULL,
status TINYINT(2) NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL
CHECK (name_translations IS NULL OR JSON_VALID(name_translations))
);
SQL
end
def down
execute <<-SQL
DROP TABLE categories;
SQL
end
But now when i do run in rails console:
data = Category.first
#<Category:0x00000000042e1450
id: 1,
name_translations: "{"en": "food", "es": "comida"}",
status: 0,
created_at: Fri, 05 Jan 2018 06:44:07 UTC +00:00,
updated_at: Fri, 05 Jan 2018 06:44:07 UTC +00:00>
data.name
// It returns key "en" not the key value "food" from {"en": "food", "es": "comida"}
I am using mariadb 10.3.0 version with Rails 5.1.4 with this setup
create_table :posts do |t|
t.column :title_translations, 'json'
t.timestamps
end
Error:
Caused by:
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json NOT NULL,
The text was updated successfully, but these errors were encountered: