SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

Does a multiclassed wizard start with a spellbook?

Minimizing medical costs with HSA

Boss has banned cycling to work because he thinks it's unsafe

Is there a typical layout to blocking installed for backing in new construction framing?

In the Seventh Seal why does Death let the chess game happen?

Why has Novell never written its own boot loader?

Should I warn my boss I might take sick leave

Why is the saxophone not common in classical repertoire?

Is it possible to spoof an IP address to an exact number?

Motorcyle Chain needs to be cleaned every time you lube it?

Bypass with wrong cvv of debit card and getting OTP

Do we have a much compact and generalized version of erase–remove idiom?

how can i make this execution plan more efficient?

Why did moving the mouse cursor cause Windows 95 to run more quickly?

What's the big deal about the Nazgûl losing their horses?

Has chattel slavery ever been used as a criminal punishment in the USA since the passage of the Thirteenth Amendment?

Show that there are infinitely more problems than we will ever be able to compute

Explain how 'Sharing the burden' puzzle from Professor Layton and the Miracle Mask should be solved

PhD: When to quit and move on?

Do intermediate subdomains need to exist?

Who pays for increased security measures on flights to the US?

Can mxd files be under version control?

How to supply water to a coastal desert town with no rain and no freshwater aquifers?

What do you call the angle of the direction of an airplane?



SQL error code 1064 with creating Laravel foreign keys


Foreign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I have a table bankaccounts. In there I have a column 'user_id' that refers to the id of in the user table.



Now I want to add a foreign key to that column, but then I get this error.




>
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned not null, created_at timestamp null, updated_at timestamp null) def' at line 1 (SQL: create table bankaccounts (id bigint unsigned not null auto_increment primary key, user_id int unsigned not null, accountnumber varchar(191) not null, bank varchar(191) not null, user_name varchar(191) unsigned not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')




I've already tried it with just the minimum change. Only add a foreign key on the user_id column.



I have the standard Laravel users migration and this is the bankaccounts migration.



public function up()

Schema::create('bankaccounts', function (Blueprint $table)
$table->bigIncrements('id');
$table->integer('user_id')->unsigned();
$table->string('accountnumber')->unique();
$table->string('bank');
$table->string('user_name');
$table->timestamps();
);

Schema::table('bankaccounts', function($table)
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('user_name')->references('name')->on('users')->onDelete('cascade');
);



I have no idea what I'm doing wrong, because I see tutorials online that also try it with the id from the users table, and they succeed.










share|improve this question






























    -1















    I have a table bankaccounts. In there I have a column 'user_id' that refers to the id of in the user table.



    Now I want to add a foreign key to that column, but then I get this error.




    >
    SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned not null, created_at timestamp null, updated_at timestamp null) def' at line 1 (SQL: create table bankaccounts (id bigint unsigned not null auto_increment primary key, user_id int unsigned not null, accountnumber varchar(191) not null, bank varchar(191) not null, user_name varchar(191) unsigned not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')




    I've already tried it with just the minimum change. Only add a foreign key on the user_id column.



    I have the standard Laravel users migration and this is the bankaccounts migration.



    public function up()

    Schema::create('bankaccounts', function (Blueprint $table)
    $table->bigIncrements('id');
    $table->integer('user_id')->unsigned();
    $table->string('accountnumber')->unique();
    $table->string('bank');
    $table->string('user_name');
    $table->timestamps();
    );

    Schema::table('bankaccounts', function($table)
    $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
    $table->foreign('user_name')->references('name')->on('users')->onDelete('cascade');
    );



    I have no idea what I'm doing wrong, because I see tutorials online that also try it with the id from the users table, and they succeed.










    share|improve this question


























      -1












      -1








      -1








      I have a table bankaccounts. In there I have a column 'user_id' that refers to the id of in the user table.



      Now I want to add a foreign key to that column, but then I get this error.




      >
      SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned not null, created_at timestamp null, updated_at timestamp null) def' at line 1 (SQL: create table bankaccounts (id bigint unsigned not null auto_increment primary key, user_id int unsigned not null, accountnumber varchar(191) not null, bank varchar(191) not null, user_name varchar(191) unsigned not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')




      I've already tried it with just the minimum change. Only add a foreign key on the user_id column.



      I have the standard Laravel users migration and this is the bankaccounts migration.



      public function up()

      Schema::create('bankaccounts', function (Blueprint $table)
      $table->bigIncrements('id');
      $table->integer('user_id')->unsigned();
      $table->string('accountnumber')->unique();
      $table->string('bank');
      $table->string('user_name');
      $table->timestamps();
      );

      Schema::table('bankaccounts', function($table)
      $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
      $table->foreign('user_name')->references('name')->on('users')->onDelete('cascade');
      );



      I have no idea what I'm doing wrong, because I see tutorials online that also try it with the id from the users table, and they succeed.










      share|improve this question
















      I have a table bankaccounts. In there I have a column 'user_id' that refers to the id of in the user table.



      Now I want to add a foreign key to that column, but then I get this error.




      >
      SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned not null, created_at timestamp null, updated_at timestamp null) def' at line 1 (SQL: create table bankaccounts (id bigint unsigned not null auto_increment primary key, user_id int unsigned not null, accountnumber varchar(191) not null, bank varchar(191) not null, user_name varchar(191) unsigned not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')




      I've already tried it with just the minimum change. Only add a foreign key on the user_id column.



      I have the standard Laravel users migration and this is the bankaccounts migration.



      public function up()

      Schema::create('bankaccounts', function (Blueprint $table)
      $table->bigIncrements('id');
      $table->integer('user_id')->unsigned();
      $table->string('accountnumber')->unique();
      $table->string('bank');
      $table->string('user_name');
      $table->timestamps();
      );

      Schema::table('bankaccounts', function($table)
      $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
      $table->foreign('user_name')->references('name')->on('users')->onDelete('cascade');
      );



      I have no idea what I'm doing wrong, because I see tutorials online that also try it with the id from the users table, and they succeed.







      php sql laravel






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 19:25







      idontunderstandarrays

















      asked Mar 25 at 19:11









      idontunderstandarraysidontunderstandarrays

      8910 bronze badges




      8910 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          3














          You can't have a "unsigned" varchar.



          You have



          user_name varchar(191) unsigned not null


          change it to



          user_name varchar(191) not null





          share|improve this answer


















          • 2





            In the laravel migration, this is caused by $table->string('user_name')->unsigned();

            – Devon
            Mar 25 at 19:16






          • 1





            Technically, because this is Laravel, OP needs to change $table->string('user_name')->unsigned(); to $table->string('user_name');.

            – Ed Cottrell
            Mar 25 at 19:16












          • I edited my post. Even without the name, it still won't work. Now I'm getting this error: General error: 1215 Cannot add foreign key constraint (SQL: alter table bankaccounts add constraint bankaccounts_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

            – idontunderstandarrays
            Mar 25 at 19:17






          • 1





            @idontunderstandarrays That's a different problem and should be asked in a different question.

            – Ed Cottrell
            Mar 25 at 19:17











          • @EdCottrell Okay well, I changed it to your suggestion, removed the foreign key for the user_id and I'm also getting that same error.

            – idontunderstandarrays
            Mar 25 at 19:19










          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
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344918%2fsql-error-code-1064-with-creating-laravel-foreign-keys%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          You can't have a "unsigned" varchar.



          You have



          user_name varchar(191) unsigned not null


          change it to



          user_name varchar(191) not null





          share|improve this answer


















          • 2





            In the laravel migration, this is caused by $table->string('user_name')->unsigned();

            – Devon
            Mar 25 at 19:16






          • 1





            Technically, because this is Laravel, OP needs to change $table->string('user_name')->unsigned(); to $table->string('user_name');.

            – Ed Cottrell
            Mar 25 at 19:16












          • I edited my post. Even without the name, it still won't work. Now I'm getting this error: General error: 1215 Cannot add foreign key constraint (SQL: alter table bankaccounts add constraint bankaccounts_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

            – idontunderstandarrays
            Mar 25 at 19:17






          • 1





            @idontunderstandarrays That's a different problem and should be asked in a different question.

            – Ed Cottrell
            Mar 25 at 19:17











          • @EdCottrell Okay well, I changed it to your suggestion, removed the foreign key for the user_id and I'm also getting that same error.

            – idontunderstandarrays
            Mar 25 at 19:19















          3














          You can't have a "unsigned" varchar.



          You have



          user_name varchar(191) unsigned not null


          change it to



          user_name varchar(191) not null





          share|improve this answer


















          • 2





            In the laravel migration, this is caused by $table->string('user_name')->unsigned();

            – Devon
            Mar 25 at 19:16






          • 1





            Technically, because this is Laravel, OP needs to change $table->string('user_name')->unsigned(); to $table->string('user_name');.

            – Ed Cottrell
            Mar 25 at 19:16












          • I edited my post. Even without the name, it still won't work. Now I'm getting this error: General error: 1215 Cannot add foreign key constraint (SQL: alter table bankaccounts add constraint bankaccounts_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

            – idontunderstandarrays
            Mar 25 at 19:17






          • 1





            @idontunderstandarrays That's a different problem and should be asked in a different question.

            – Ed Cottrell
            Mar 25 at 19:17











          • @EdCottrell Okay well, I changed it to your suggestion, removed the foreign key for the user_id and I'm also getting that same error.

            – idontunderstandarrays
            Mar 25 at 19:19













          3












          3








          3







          You can't have a "unsigned" varchar.



          You have



          user_name varchar(191) unsigned not null


          change it to



          user_name varchar(191) not null





          share|improve this answer













          You can't have a "unsigned" varchar.



          You have



          user_name varchar(191) unsigned not null


          change it to



          user_name varchar(191) not null






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 at 19:15









          LulceltechLulceltech

          1,2783 silver badges14 bronze badges




          1,2783 silver badges14 bronze badges







          • 2





            In the laravel migration, this is caused by $table->string('user_name')->unsigned();

            – Devon
            Mar 25 at 19:16






          • 1





            Technically, because this is Laravel, OP needs to change $table->string('user_name')->unsigned(); to $table->string('user_name');.

            – Ed Cottrell
            Mar 25 at 19:16












          • I edited my post. Even without the name, it still won't work. Now I'm getting this error: General error: 1215 Cannot add foreign key constraint (SQL: alter table bankaccounts add constraint bankaccounts_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

            – idontunderstandarrays
            Mar 25 at 19:17






          • 1





            @idontunderstandarrays That's a different problem and should be asked in a different question.

            – Ed Cottrell
            Mar 25 at 19:17











          • @EdCottrell Okay well, I changed it to your suggestion, removed the foreign key for the user_id and I'm also getting that same error.

            – idontunderstandarrays
            Mar 25 at 19:19












          • 2





            In the laravel migration, this is caused by $table->string('user_name')->unsigned();

            – Devon
            Mar 25 at 19:16






          • 1





            Technically, because this is Laravel, OP needs to change $table->string('user_name')->unsigned(); to $table->string('user_name');.

            – Ed Cottrell
            Mar 25 at 19:16












          • I edited my post. Even without the name, it still won't work. Now I'm getting this error: General error: 1215 Cannot add foreign key constraint (SQL: alter table bankaccounts add constraint bankaccounts_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

            – idontunderstandarrays
            Mar 25 at 19:17






          • 1





            @idontunderstandarrays That's a different problem and should be asked in a different question.

            – Ed Cottrell
            Mar 25 at 19:17











          • @EdCottrell Okay well, I changed it to your suggestion, removed the foreign key for the user_id and I'm also getting that same error.

            – idontunderstandarrays
            Mar 25 at 19:19







          2




          2





          In the laravel migration, this is caused by $table->string('user_name')->unsigned();

          – Devon
          Mar 25 at 19:16





          In the laravel migration, this is caused by $table->string('user_name')->unsigned();

          – Devon
          Mar 25 at 19:16




          1




          1





          Technically, because this is Laravel, OP needs to change $table->string('user_name')->unsigned(); to $table->string('user_name');.

          – Ed Cottrell
          Mar 25 at 19:16






          Technically, because this is Laravel, OP needs to change $table->string('user_name')->unsigned(); to $table->string('user_name');.

          – Ed Cottrell
          Mar 25 at 19:16














          I edited my post. Even without the name, it still won't work. Now I'm getting this error: General error: 1215 Cannot add foreign key constraint (SQL: alter table bankaccounts add constraint bankaccounts_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

          – idontunderstandarrays
          Mar 25 at 19:17





          I edited my post. Even without the name, it still won't work. Now I'm getting this error: General error: 1215 Cannot add foreign key constraint (SQL: alter table bankaccounts add constraint bankaccounts_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

          – idontunderstandarrays
          Mar 25 at 19:17




          1




          1





          @idontunderstandarrays That's a different problem and should be asked in a different question.

          – Ed Cottrell
          Mar 25 at 19:17





          @idontunderstandarrays That's a different problem and should be asked in a different question.

          – Ed Cottrell
          Mar 25 at 19:17













          @EdCottrell Okay well, I changed it to your suggestion, removed the foreign key for the user_id and I'm also getting that same error.

          – idontunderstandarrays
          Mar 25 at 19:19





          @EdCottrell Okay well, I changed it to your suggestion, removed the foreign key for the user_id and I'm also getting that same error.

          – idontunderstandarrays
          Mar 25 at 19:19








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344918%2fsql-error-code-1064-with-creating-laravel-foreign-keys%23new-answer', 'question_page');

          );

          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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현