laravel-migrations

How to set auto increment into non primary key?

旧城冷巷雨未停 提交于 2019-12-12 18:17:22
问题 How would I set a database auto increment field that is not a primary key on the creation method? The only way is using a raw query? DB::statement('ALTER TABLE table CHANGE field field INT(10)AUTO_INCREMENT'); 回答1: It is not implemented to do so. However, I found this over at the Laravel Forums: Schema::table('table', function(Blueprint $t) { // Add the Auto-Increment column $t->increments("some_column"); // Remove the primary key $t->dropPrimary("table_some_column_primary"); // Set the

Where to put migration within a Laravel 5.1 package?

家住魔仙堡 提交于 2019-12-12 11:03:28
问题 Well, I do have a package take I only use alongside with my system. I do have migrations for that package (it was build on Laravel 4.2, and I'm upgrading it). That being said: On my package (former workbench) on Laravel 5.1, where do I put and how do I run my migrations? Does any of you guys know how to deal with this? UPDATE : This is not the case of a simple migration. Back on laravel 4.*, we were able to maintain migrations for each package (if it was so desirable), and I do have some

How would I override Laravel 5.3 sql grammar

对着背影说爱祢 提交于 2019-12-12 01:57:03
问题 How would I set Laravel 5.3 to use VARCHAR over NVARCHAR for migrations on mssql? Is there even a way to do this? This question also applies to SMALLDATETIME over DATETIME. 回答1: I created a package that lets you do custom migrations without all the hassle of extending everything yourself. https://github.com/shiftonelabs/laravel-nomad Once you install the package, you just change your migration to use the new passthru method, and you can give it the definition you want for your field. // pass

Laravel 5.x Database Triggers and possible best practices

ⅰ亾dé卋堺 提交于 2019-12-11 02:27:02
问题 This post is to sort-of inform and ask a question. Hello all, I'm developing a large system that puts triggers to good use. We're currently running the server-side on Laravel 5.2 with php 7 using phpmyadmin. Within Laravel there isn't really much solid documentation on how to use a trigger through migrations and from what I've discovered you mostly have to do it "raw". Below is a simple example, that I know of, on how to write a trigger in a migration: class CreateAccountTriggerTable extends

How to add comment to table (not column) in Laravel 5 migration?

江枫思渺然 提交于 2019-12-10 02:00:44
问题 How to add comment to table (ot column) in Laravel 5 migration? I currently know how to add comment to column like: $table->tinyInteger('status')->comment('0: requested; -1: rejected; 1:confirmed'); But what about table? 回答1: Currently, Laravel does not allow (does not have functionality) to put comment on tables, so You have to use workaround in Your migration: DB::statement("ALTER TABLE `<YOUR_TABLE>` comment '<COMMENT>'"); 回答2: For now there are no any option exist to add table comment

How to run laravel migrations without artisan (using code)

对着背影说爱祢 提交于 2019-12-06 07:30:33
问题 I recently hosted a laravel project (for a customer) on shared hosting, after failed attempts to get access to the server via ssh I contacted the host who informed me that ssh service was not available for my customers hosting plan, that means I have no access to terminal and can't use artisan. I know how to write a php script that will create sql tables but just before that I was wondering if theres a shortcut to this with laravel since the migrations(tables) are already defined. What I want

Laravel timestamps() doesn't create CURRENT_TIMESTAMP

可紊 提交于 2019-12-05 16:49:08
问题 I have a migration that has the timestamps() method, and then I have a seed to seed this table. Schema::create('mytable', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->timestamps(); }); The seed looks like this: DB::table('mytable')->insert([ [ 'title' => 'My Awesome Title' ] ]); When it all gets run using: php artisan migrate:refresh --seed The item gets inserted, but the values of created_at and updated_at are both 0000-00-00 00:00:00 why are they

How to add comment to table (not column) in Laravel 5 migration?

☆樱花仙子☆ 提交于 2019-12-05 02:49:50
How to add comment to table (ot column) in Laravel 5 migration? I currently know how to add comment to column like: $table->tinyInteger('status')->comment('0: requested; -1: rejected; 1:confirmed'); But what about table? Currently, Laravel does not allow (does not have functionality) to put comment on tables, so You have to use workaround in Your migration: DB::statement("ALTER TABLE `<YOUR_TABLE>` comment '<COMMENT>'"); For now there are no any option exist to add table comment like column add but then after you want to add the comment to table than you must have to use "DB" to add the

PDOException (1044) SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge'

微笑、不失礼 提交于 2019-12-04 04:29:35
问题 I am using Laravel 5 and getting the following exception: PDOException (1044) SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge' My database configuration file is: <?php return [ /* |-------------------------------------------------------------------------- | PDO Fetch Style |-------------------------------------------------------------------------- | | By default, database results will be returned as instances of the PHP | stdClass object; however, you may

Laravel timestamps() doesn't create CURRENT_TIMESTAMP

◇◆丶佛笑我妖孽 提交于 2019-12-04 00:48:07
I have a migration that has the timestamps() method, and then I have a seed to seed this table. Schema::create('mytable', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->timestamps(); }); The seed looks like this: DB::table('mytable')->insert([ [ 'title' => 'My Awesome Title' ] ]); When it all gets run using: php artisan migrate:refresh --seed The item gets inserted, but the values of created_at and updated_at are both 0000-00-00 00:00:00 why are they not set correctly? here are the column schemes that it creates: `created_at` TIMESTAMP NOT NULL DEFAULT