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

With Mariadb 10.3.0 version json_translate not working #9

Open
chetanrana2702 opened this issue Jan 5, 2018 · 1 comment
Open

With Mariadb 10.3.0 version json_translate not working #9

chetanrana2702 opened this issue Jan 5, 2018 · 1 comment

Comments

@chetanrana2702
Copy link

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,

@chetanrana2702
Copy link
Author

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"}

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

No branches or pull requests

1 participant