Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.08k stars 885 forks source link

Unknown database type enum requested #236

Closed ChrisThompsonTLDR closed 7 years ago

ChrisThompsonTLDR commented 7 years ago

It's exactly this pull: #176

Running MariaDB 10.

DBALException in AbstractPlatform.php line 423:
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

enum-missing

My composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*",

        "barryvdh/laravel-debugbar": "^2.2",
        "laravelcollective/html": "5.3.*",
        "predis/predis": "~1.0",
        "gloudemans/shoppingcart": "^2.2",
        "backpack/base": "^0.7.6",
        "backpack/crud": "3.1.*"
    },
tabacitu commented 7 years ago

Hmm. Never tried Backpack on MariaDB. Theoretically it should work fine, but only the features that Eloquent supports for MariaDB.

It looks to me like the "enum" column type isn't supported by DBAL, so it's not supported by Eloquent, so it's not supported by Backpack :-)

Can you change that column type to string and use a select_from_array field?

Cheers!

ChrisThompsonTLDR commented 7 years ago

Laravel and Eloquent support enum on MariaDB as far as I understand. I've used MariaDB to back dozens of Laravel 5.2 and 5.3 projects that have enum fields and have never encountered an issue.

tabacitu commented 7 years ago

Ok... in that case, try

Does it work that way? setFromDb() is pretty hit-and-miss right now, but it could be a real powerhouse in the future.

Cheers!

ChrisThompsonTLDR commented 7 years ago

Interesting, that works.

I removed $this->crud->setFromDb() and manually add the columns and fields.

Feel free to ping me if you want help testing changes to setFromDb() on MariaDB.

tabacitu commented 7 years ago

Glad it worked. Ok, great, thanks! Cheers.

ChrisThompsonTLDR commented 7 years ago
$this->crud->addField([
    'name'  => 'plan',
    'type'  => 'enum',
]);

This appears to work properly, so I don't think it's the DBAL lib or Eloquent. It must be something about the way setFromDB() gets information from the DB about the enum field.

ryancwalsh commented 7 years ago

@ChrisThompsonTLDR enum is commented out in the source here, and I wonder if that's related to the problem: https://github.com/Laravel-Backpack/CRUD/blob/6b2d202c714f36ed0fea75136b967c0f07e22d1e/src/PanelTraits/AutoSet.php#L96

I wish Laravel and Backpack could handle MySql enum columns.

mbasiddeq commented 7 years ago

you have to register enum type with registerDoctrineTypeMapping

i made it as helper function and call it before setFromDb , like this:

Helpers::setDoctrineTypesMapping(); $this->crud->setFromDb()


static public function setDoctrineTypesMapping(){ $types = ['enum' => 'string']; $platform = DB::getDoctrineConnection()->getDatabasePlatform(); foreach ($types as $type_key => $type_value) { if (!$platform->hasDoctrineTypeMappingFor($type_key)) { $platform->registerDoctrineTypeMapping($type_key, $type_value); } } }

bosz commented 7 years ago

@tabacitu commenting out the // $this->crud->setFromDb(); works. Thanks.

lloy0076 commented 7 years ago

@bosz - I don't suppose you'd mind mentioning what version of the DB you were using - it seems some have mentioned MariaDB vs MySQL and MySQL itself isn't always consistent between minor versions?

theyush commented 6 years ago

I'm using pagekit and I'm having the same error where exactly I have to comment out this? // $this->crud->setFromDb();