mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
enum not supported #5599
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wsalazar on GitHub (Jul 5, 2017).
Good afternoon,
I have an issue with the mysql enum type. My company uses a framework that is no longer supported, Kohana 3.x. We have a schema that uses the enum type. I've read some documentation that says that Doctrine2 doesn't support enum because enum has state while Doctrine2 does not. That is to say, enum comes predefined with values already and Doctrine doesn't like that.
This quote can be found in the following link that I provided below. Last sentence 2nd paragraph.
So what I had to do is create my own type.
I followed this:
Doctrine Documentation for Enums. I created the generic EnumType class. I then created my Enum type called Enumscheduletype with the following code:
In my entity this is how I'm mapping my enum type field.
However, when I ran vendor/bin/doctrine orm:schema-tool:update --dump-sql.....
I got the following error.
I then realized that in a table that I have in the db I have an enum type. Doctrine didn't like reading it.
So I found out where:
I had to hack Doctrine so that it would recognize my type. Notice the "Piece of code that I added in the code above. This is in the file: vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php. Problem is, I should not have to hack Doctrine. Is there another way around this? How can I hook into Doctrine so that upon reading my schema it'll recognize my type and not what it reads from the db.
@Ocramius commented on GitHub (Jul 5, 2017):
See:
https://stackoverflow.com/questions/8750724/what-do-you-use-instead-of-enum-in-doctrine2/9057352
*
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/mysql-enums.html#solution-1-mapping-to-varchars
(specifically, this is the simplest/cleanest solution)
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
On Wed, Jul 5, 2017 at 10:46 PM, was notifications@github.com wrote:
@wsalazar commented on GitHub (Jul 5, 2017):
Thanks. I tried that. Unfortunately, the columnDefinition and the options do not play nice together.
I tried this:
I get this when I do the --dump-sql:
ALTER TABLE test_table ADD frequency ENUM('daily','weekly','monthly');
It should be:
ALTER TABLE test_table ADD frequency ENUM('daily','weekly','monthly') default 'weekly' NOT NULL;
@Ocramius commented on GitHub (Jul 5, 2017):
columnDefinitionwill ALWAYS fail at schema introspection, because youare already in "custom stuff land".
This is perfectly OK: you should just use migrations anyway when
provisioning environments, which means that you will just have these pesky
diffs all over the place.
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
On Thu, Jul 6, 2017 at 12:52 AM, was notifications@github.com wrote:
@beberlei commented on GitHub (Dec 6, 2020):
You need to register that
$connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'YourEnumType');- however again here the statefullness is a problem, because what enum is meant? It only works when you use exactly one enum.This is not something we want to support, as we don't use it ourselves internally. You can't benefit from all schema tool features when you have a legacy schema with enums.