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

DEFAULT value in table migration cannot be executed if it is a function #11056

Closed
digirew opened this issue Nov 22, 2015 · 3 comments
Closed

Comments

@digirew
Copy link

digirew commented Nov 22, 2015

When i specify a function name as a table column default, this is wrapped into quotes so when executed the function isn't run, its saved as a string.

This gives an error fortunately because UUID col can't have a default string value of this type.

Schema::create('products', function(Blueprint $table)
        {
            $table->uuid('id')->default('gen_random_uuid()')->primary('products_pkey');
            $table->string('name')->nullable();
            $table->string('max_projects')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });
@jairovsky
Copy link
Contributor

Try with DB::raw:

 $table->uuid('id')->default(DB::raw('gen_random_uuid()'))->primary('products_pkey');

@bradleybensmith
Copy link

You can't use a function as a default value in MySQL. It has to be a constant. To generate a UUID, you'd have to either use a trigger or do it manually.

@jairovsky
Copy link
Contributor

gen_random_uuid() is a Postgre function.

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

4 participants