Database table not created after running php artisan migrate
I am using laravel 5.7 and I noticed that my database table was not created after running php artisan migrate even when my .env has been properly updated and everything seems very correct from my angle.
After much research, I stumbled into a video that said I have to go to AppServiceProver.php and add some lines of codes as follows:
Update AppServiceProver.php from:
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
To:
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
/**
* Register any application services.
A line of code was added on line 6 (use IlluminateSupportFacadesSchema;) and the Schema was called upon on line 17 (Schema::defaultStringLength(191);).
Immediately I added those lines of codes to my AppServiceProver.php, and then ran php artisan migrate; all my table just got created immediately on my database.
But the unfortunate thing for me as a learner is that the man said he doesn't know why the tables were not created at first and why the codes had to be added to AppServiceProvider.php. That he had the error and stumbled into the answer too.
As a learner, I am curious and want to know why I had that challenge and why those lines of codes solved them.
Thank you very much for your kind answers.
php laravel
add a comment |
I am using laravel 5.7 and I noticed that my database table was not created after running php artisan migrate even when my .env has been properly updated and everything seems very correct from my angle.
After much research, I stumbled into a video that said I have to go to AppServiceProver.php and add some lines of codes as follows:
Update AppServiceProver.php from:
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
To:
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
/**
* Register any application services.
A line of code was added on line 6 (use IlluminateSupportFacadesSchema;) and the Schema was called upon on line 17 (Schema::defaultStringLength(191);).
Immediately I added those lines of codes to my AppServiceProver.php, and then ran php artisan migrate; all my table just got created immediately on my database.
But the unfortunate thing for me as a learner is that the man said he doesn't know why the tables were not created at first and why the codes had to be added to AppServiceProvider.php. That he had the error and stumbled into the answer too.
As a learner, I am curious and want to know why I had that challenge and why those lines of codes solved them.
Thank you very much for your kind answers.
php laravel
what about your DB? What version and etc.?
– autumnrustle
Dec 29 '18 at 21:29
@Sam O, firstly delete migration file and tables in your target DB, and run againphp artisan migratebecause your migration file already made when you first tried. check this link...laravel-news.com/laravel-5-4-key-too-long-error good luck!
– JsWizard
Dec 29 '18 at 21:34
@autumnrustle, I am using XAMPP Control Panel v 3.2.2
– Sam O.
Dec 29 '18 at 21:37
I think problem in your DB. Some DB have max length of char and varchar fields less then 255. So you can in all migrations set length of this fields less then 255. Or you can set it by default (like yor do)
– autumnrustle
Dec 29 '18 at 21:46
to reload all migrations you can usephp artisan migrate:refresh
– autumnrustle
Dec 29 '18 at 21:49
add a comment |
I am using laravel 5.7 and I noticed that my database table was not created after running php artisan migrate even when my .env has been properly updated and everything seems very correct from my angle.
After much research, I stumbled into a video that said I have to go to AppServiceProver.php and add some lines of codes as follows:
Update AppServiceProver.php from:
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
To:
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
/**
* Register any application services.
A line of code was added on line 6 (use IlluminateSupportFacadesSchema;) and the Schema was called upon on line 17 (Schema::defaultStringLength(191);).
Immediately I added those lines of codes to my AppServiceProver.php, and then ran php artisan migrate; all my table just got created immediately on my database.
But the unfortunate thing for me as a learner is that the man said he doesn't know why the tables were not created at first and why the codes had to be added to AppServiceProvider.php. That he had the error and stumbled into the answer too.
As a learner, I am curious and want to know why I had that challenge and why those lines of codes solved them.
Thank you very much for your kind answers.
php laravel
I am using laravel 5.7 and I noticed that my database table was not created after running php artisan migrate even when my .env has been properly updated and everything seems very correct from my angle.
After much research, I stumbled into a video that said I have to go to AppServiceProver.php and add some lines of codes as follows:
Update AppServiceProver.php from:
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
To:
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
/**
* Register any application services.
A line of code was added on line 6 (use IlluminateSupportFacadesSchema;) and the Schema was called upon on line 17 (Schema::defaultStringLength(191);).
Immediately I added those lines of codes to my AppServiceProver.php, and then ran php artisan migrate; all my table just got created immediately on my database.
But the unfortunate thing for me as a learner is that the man said he doesn't know why the tables were not created at first and why the codes had to be added to AppServiceProvider.php. That he had the error and stumbled into the answer too.
As a learner, I am curious and want to know why I had that challenge and why those lines of codes solved them.
Thank you very much for your kind answers.
php laravel
php laravel
edited Dec 31 '18 at 15:07
Sam O.
asked Dec 29 '18 at 21:24
Sam O.Sam O.
15
15
what about your DB? What version and etc.?
– autumnrustle
Dec 29 '18 at 21:29
@Sam O, firstly delete migration file and tables in your target DB, and run againphp artisan migratebecause your migration file already made when you first tried. check this link...laravel-news.com/laravel-5-4-key-too-long-error good luck!
– JsWizard
Dec 29 '18 at 21:34
@autumnrustle, I am using XAMPP Control Panel v 3.2.2
– Sam O.
Dec 29 '18 at 21:37
I think problem in your DB. Some DB have max length of char and varchar fields less then 255. So you can in all migrations set length of this fields less then 255. Or you can set it by default (like yor do)
– autumnrustle
Dec 29 '18 at 21:46
to reload all migrations you can usephp artisan migrate:refresh
– autumnrustle
Dec 29 '18 at 21:49
add a comment |
what about your DB? What version and etc.?
– autumnrustle
Dec 29 '18 at 21:29
@Sam O, firstly delete migration file and tables in your target DB, and run againphp artisan migratebecause your migration file already made when you first tried. check this link...laravel-news.com/laravel-5-4-key-too-long-error good luck!
– JsWizard
Dec 29 '18 at 21:34
@autumnrustle, I am using XAMPP Control Panel v 3.2.2
– Sam O.
Dec 29 '18 at 21:37
I think problem in your DB. Some DB have max length of char and varchar fields less then 255. So you can in all migrations set length of this fields less then 255. Or you can set it by default (like yor do)
– autumnrustle
Dec 29 '18 at 21:46
to reload all migrations you can usephp artisan migrate:refresh
– autumnrustle
Dec 29 '18 at 21:49
what about your DB? What version and etc.?
– autumnrustle
Dec 29 '18 at 21:29
what about your DB? What version and etc.?
– autumnrustle
Dec 29 '18 at 21:29
@Sam O, firstly delete migration file and tables in your target DB, and run again
php artisan migrate because your migration file already made when you first tried. check this link...laravel-news.com/laravel-5-4-key-too-long-error good luck!– JsWizard
Dec 29 '18 at 21:34
@Sam O, firstly delete migration file and tables in your target DB, and run again
php artisan migrate because your migration file already made when you first tried. check this link...laravel-news.com/laravel-5-4-key-too-long-error good luck!– JsWizard
Dec 29 '18 at 21:34
@autumnrustle, I am using XAMPP Control Panel v 3.2.2
– Sam O.
Dec 29 '18 at 21:37
@autumnrustle, I am using XAMPP Control Panel v 3.2.2
– Sam O.
Dec 29 '18 at 21:37
I think problem in your DB. Some DB have max length of char and varchar fields less then 255. So you can in all migrations set length of this fields less then 255. Or you can set it by default (like yor do)
– autumnrustle
Dec 29 '18 at 21:46
I think problem in your DB. Some DB have max length of char and varchar fields less then 255. So you can in all migrations set length of this fields less then 255. Or you can set it by default (like yor do)
– autumnrustle
Dec 29 '18 at 21:46
to reload all migrations you can use
php artisan migrate:refresh– autumnrustle
Dec 29 '18 at 21:49
to reload all migrations you can use
php artisan migrate:refresh– autumnrustle
Dec 29 '18 at 21:49
add a comment |
2 Answers
2
active
oldest
votes
You have to set defaultStringLength to switch the character set, utf8mb4
The utf8mb4 character set is useful because nowadays we need support for storing not only language characters but also symbols, newly introduced emojis, and so on. Hope you got it!
add a comment |
Sorry for the late reply While running the migration you may get the error as
Specified key was too long; max key length is 767 bytes
this is because
Just For Example
You Migration may look
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
While running the migration it will look for length for the each field
such as
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name',50);
$table->string('email',100)->unique();
$table->timestamp('email_verified_at',150)->nullable();
$table->string('password',150);
$table->rememberToken();
$table->timestamps();
});
}
If you are lazy and need to add comman length to add all the fileds
use Schema::defaultStringLength(191); inside boot Method of AppServiceProvider
By Adding this IT will add the length of the fileds as 191
Thats it
Thank you for the explanation
– Sam O.
Dec 31 '18 at 14:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53973438%2fdatabase-table-not-created-after-running-php-artisan-migrate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have to set defaultStringLength to switch the character set, utf8mb4
The utf8mb4 character set is useful because nowadays we need support for storing not only language characters but also symbols, newly introduced emojis, and so on. Hope you got it!
add a comment |
You have to set defaultStringLength to switch the character set, utf8mb4
The utf8mb4 character set is useful because nowadays we need support for storing not only language characters but also symbols, newly introduced emojis, and so on. Hope you got it!
add a comment |
You have to set defaultStringLength to switch the character set, utf8mb4
The utf8mb4 character set is useful because nowadays we need support for storing not only language characters but also symbols, newly introduced emojis, and so on. Hope you got it!
You have to set defaultStringLength to switch the character set, utf8mb4
The utf8mb4 character set is useful because nowadays we need support for storing not only language characters but also symbols, newly introduced emojis, and so on. Hope you got it!
answered Dec 29 '18 at 22:05
Muhammad ManshaMuhammad Mansha
206
206
add a comment |
add a comment |
Sorry for the late reply While running the migration you may get the error as
Specified key was too long; max key length is 767 bytes
this is because
Just For Example
You Migration may look
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
While running the migration it will look for length for the each field
such as
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name',50);
$table->string('email',100)->unique();
$table->timestamp('email_verified_at',150)->nullable();
$table->string('password',150);
$table->rememberToken();
$table->timestamps();
});
}
If you are lazy and need to add comman length to add all the fileds
use Schema::defaultStringLength(191); inside boot Method of AppServiceProvider
By Adding this IT will add the length of the fileds as 191
Thats it
Thank you for the explanation
– Sam O.
Dec 31 '18 at 14:53
add a comment |
Sorry for the late reply While running the migration you may get the error as
Specified key was too long; max key length is 767 bytes
this is because
Just For Example
You Migration may look
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
While running the migration it will look for length for the each field
such as
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name',50);
$table->string('email',100)->unique();
$table->timestamp('email_verified_at',150)->nullable();
$table->string('password',150);
$table->rememberToken();
$table->timestamps();
});
}
If you are lazy and need to add comman length to add all the fileds
use Schema::defaultStringLength(191); inside boot Method of AppServiceProvider
By Adding this IT will add the length of the fileds as 191
Thats it
Thank you for the explanation
– Sam O.
Dec 31 '18 at 14:53
add a comment |
Sorry for the late reply While running the migration you may get the error as
Specified key was too long; max key length is 767 bytes
this is because
Just For Example
You Migration may look
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
While running the migration it will look for length for the each field
such as
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name',50);
$table->string('email',100)->unique();
$table->timestamp('email_verified_at',150)->nullable();
$table->string('password',150);
$table->rememberToken();
$table->timestamps();
});
}
If you are lazy and need to add comman length to add all the fileds
use Schema::defaultStringLength(191); inside boot Method of AppServiceProvider
By Adding this IT will add the length of the fileds as 191
Thats it
Sorry for the late reply While running the migration you may get the error as
Specified key was too long; max key length is 767 bytes
this is because
Just For Example
You Migration may look
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
While running the migration it will look for length for the each field
such as
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name',50);
$table->string('email',100)->unique();
$table->timestamp('email_verified_at',150)->nullable();
$table->string('password',150);
$table->rememberToken();
$table->timestamps();
});
}
If you are lazy and need to add comman length to add all the fileds
use Schema::defaultStringLength(191); inside boot Method of AppServiceProvider
By Adding this IT will add the length of the fileds as 191
Thats it
answered Dec 31 '18 at 6:59
Manojkiran.AManojkiran.A
31228
31228
Thank you for the explanation
– Sam O.
Dec 31 '18 at 14:53
add a comment |
Thank you for the explanation
– Sam O.
Dec 31 '18 at 14:53
Thank you for the explanation
– Sam O.
Dec 31 '18 at 14:53
Thank you for the explanation
– Sam O.
Dec 31 '18 at 14:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53973438%2fdatabase-table-not-created-after-running-php-artisan-migrate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what about your DB? What version and etc.?
– autumnrustle
Dec 29 '18 at 21:29
@Sam O, firstly delete migration file and tables in your target DB, and run again
php artisan migratebecause your migration file already made when you first tried. check this link...laravel-news.com/laravel-5-4-key-too-long-error good luck!– JsWizard
Dec 29 '18 at 21:34
@autumnrustle, I am using XAMPP Control Panel v 3.2.2
– Sam O.
Dec 29 '18 at 21:37
I think problem in your DB. Some DB have max length of char and varchar fields less then 255. So you can in all migrations set length of this fields less then 255. Or you can set it by default (like yor do)
– autumnrustle
Dec 29 '18 at 21:46
to reload all migrations you can use
php artisan migrate:refresh– autumnrustle
Dec 29 '18 at 21:49