script
Using MYSQL enum in ecto migrations
I am using MYSQL instead of Postgres for my database. For Postgres it’s simple we can create a type using enum and use it in the migration to allow the values in the enum, but MYSQL doesn’t support this. Now, If I want the enum in the migrations. How can I do that with MYSQL? Let’s say this is my migration.
create table(:user) do
add(:role, :string) # 'owner', 'worker', 'manager', 'pending_approval'
add(:business_id, :string, null: false, default: "")
end
I only want to allow owner, worker, manager, pending approvals for role field.
Thanks.
Most Liked
script
I figure out a workaround for this. After creating a table with ecto migration. I executed SQL command to alter the table and add the enum column like this:
create table(:users) do
add(:business_id, :string, null: false, default: "")
end
execute "ALTER TABLE users
ADD role ENUM('owner', 'worker', 'manager', 'pending_approval');"
3
Popular in Questions
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Background
Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
Other popular topics
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
Manning 2016 Halloween weekend sale via Deal of the Day
Friday, October 28 - Half off all MEAPs - code WM102816LT
Saturday, October 29 ...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New







