abhay
How to make list in schema using MySQL as database?
While working with ecto schema connecting to Mysql as database I tried using list data type. I used {:array, :inner_type} for storing list into the database as per hex docs info Ecto.Schema — Ecto v3.14.0 .but it shows an error that MySQL doesn’t support array, so is there any solution?
Most Liked
c4710n
As a supplement at 2021…
Ecto v3 with MySQL < 5.7.8 (don’t support JSON) :
- use
:textin migrations. - use
:mapor{:array, inner_type}at schema level, and Ecto will encode and decode it for you.
Ecto v3 with MySQL >= 5.7.8:
- use
:mapor:jsonin migrations. - use
:mapor{:array, inner_type}at schema level.
michalmuskala
Some of ecto features are only supported by some adapters - MySQL in general does not support more advanced features, arrays are one of them (this is not a limitation of Ecto, but of MySQL). There are several options of emulating them - either serialising to JSON or simple comma separated string, or even having a separate table.
dsnipe
I had the same problem.
Decided to use an old plain one-to-many association instead. it’s a SQL database in the end.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








