0

I cannot migrate and make a new table field in phpmyadmin in my database it is giving me this error why?

my Modal name Setting

here is my modal as you can see I can't insert anything still coz I don't have my table in phpmyadmin.

    <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Setting extends Model
{
    //
}

my Migration

here is my migration

 public function up()
{
    Schema::create('settings', function (Blueprint $table) {
        $table->increments('id');
        $table->string('settings_code');
        $table->string('subject');
        $table->text('description');
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('settings');
}

Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'clients' already exists (SQL: create table clients (id int unsigned not null auto_increment primary key, client_code varchar(191) not null, client_name varchar(191) not null, address varchar(191) not null, tel_no varchar(191) not null, contact_person varchar(191) not null, mobile_no varchar(191) not null, email_ad varchar(191) not null, website varchar(191) not null, deleted_at timestamp null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

I want to create a new table not client table but it is giving me this error. why?

Khalifa Nikzad
  • 1,213
  • 1
  • 6
  • 17
  • use php artisan migrate:fresh it's will dropped all table and migrate new ones – MD. Jubair Mizan Dec 03 '18 at 07:58
  • Message is quite clear, table already exists. How are you calling your migrations? Can you edit your question and paste your migration? Wait "_I cannot create a new table field in phpmyadmin_" You're not using migrations but `phpmyadmin`? – brombeer Dec 03 '18 at 07:58
  • Can you provide your code? – cham Dec 03 '18 at 07:59
  • There it is sorry im just in a hurry –  Dec 03 '18 at 08:01
  • That's not a modal, but a migration. And that's not for the table `clients`, but for `settings`. If you want to re-initiate your migration use `php artisan migrate:fresh` to drop all tables (and data!!!) and run all migrations from start – brombeer Dec 03 '18 at 08:01
  • @kerbholz no I want to migrate and create new table in my phpmyadmin sorry –  Dec 03 '18 at 08:02
  • oh right ,... ill edit it again my modal has no code –  Dec 03 '18 at 08:03
  • there it is all edited please see –  Dec 03 '18 at 08:05
  • @kerbholz dude, why it worked all of a sudden when i do migrate:fresh? make a answer below i will mark your answer and one more.. why php artisan migrate didnt work? any explanation? –  Dec 03 '18 at 08:09
  • 1
    https://laravel.com/docs/5.7/migrations `php artisan migrate:fresh` drops all existing tables (and thus data) and runs your migrations from the start. So no "duplicate" tables. @MD.JubairMizan commented "the solution" first, so he should get props for an answer – brombeer Dec 03 '18 at 08:16
  • hey @kerbholz when i refresh, my data were removed. and when i register and login it creates an error why –  Dec 03 '18 at 08:27
  • Dear I have create an answer On this – MD. Jubair Mizan Dec 03 '18 at 08:28
  • We mentioned that "tables will be dropped"/"data will be lost". As for your error when registering/logging in please create a new question for that specific problem. And mention there _what_ error you get – brombeer Dec 03 '18 at 08:30

2 Answers2

3

Run:php artisan migrate:fresh

Be warned This will remove anything stored within the database so ensure you have a Seeder setup to place any relevant content back into the database.

In the event you get an Specified key was too long error on the re migrate open AppServiceProvider and add:

Schema::defaultStringLength(191); into the boot function

Ensure you add use Illuminate\Support\Facades\Schema; at the top of the AppServiceProvider file

MD. Jubair Mizan
  • 1,539
  • 1
  • 12
  • 20
0

hi try to romove your database from phpmyadmin and create again then run php artisan migrate to login go to your table user and create a user manually in BD and in your model put fillable with your data stored