اذهب إلى المحتوى
  • 0

خطأ عند تهجير الجداول في لارافيل

محمد شعفوط

السؤال

Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('google_id')->nullable();
$table->string('facebook_id')->nullable();
$table->string('country_id')->nullable()->unsigned();
$table->integer('role_id')->default('2');
$table->string('avatar')->nullable();
$table->string('avatar_original')->nullable();
$table->boolean('Account_Verification')->default(false);
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0
بتاريخ 28 دقائق مضت قال محمد شعفوط:

 Illuminate\Database\QueryException 

  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version fo
r the right syntax to use near 'unsigned null, `role_id` int not null default '2', `avatar` varchar(255) null...' at line 1 (SQL: create table `users` (`id` bigint
 unsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(255) not null, `google_id` varchar(255) null, `facebook_id` varchar(25
5) null, `country_id` varchar(255) unsigned null, `role_id` int not null default '2', `avatar` varchar(255) null, `avatar_original` varchar(255) null, `Account_Ver
ification` tinyint(1) not null default '0', `email_verified_at` timestamp null, `password` varchar(255) not null, `remember_token` varchar(100) null, `created_at`
timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at C:\xampp\htdocs\joabk\vendor\laravel\framework\src\Illuminate\Database\Connection.php:692
    688         // If an exception occurs when attempting to run a query, we'll format the error
    689         // message to include the bindings with SQL, which will make this exception a
    690         // lot more helpful to the developer instead of just the database's errors.
    691         catch (Exception $e) {
   692             throw new QueryException(
    693                 $query, $this->prepareBindings($bindings), $e
    694             );
    695         }
    696     }

  1   C:\xampp\htdocs\joabk\vendor\laravel\framework\src\Illuminate\Database\Connection.php:479
      PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your Maria
DB server version for the right syntax to use near 'unsigned null, `role_id` int not null default '2', `avatar` varchar(255) null...' at line 1")

  2   C:\xampp\htdocs\joabk\vendor\laravel\framework\src\Illuminate\Database\Connection.php:479
      PDO::prepare("create table `users` (`id` bigint unsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(255) not null, `g
oogle_id` varchar(255) null, `facebook_id` varchar(255) null, `country_id` varchar(255) unsigned null, `role_id` int not null default '2', `avatar` varchar(255) nu
ll, `avatar_original` varchar(255) null, `Account_Verification` tinyint(1) not null default '0', `email_verified_at` timestamp null, `password` varchar(255) not nu
ll, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci'")

 

 

المشكلة أنك تحاول اعطاء خاصية unsigned لعمود من نوع سلسلة نصية, وهذا غير منطقي, الخطأ بالتحديد في هذا السطر

$table->string('country_id')->nullable()->unsigned();

الخاصية unsigned هو قيد على قيمة العمود بأنه لا يمكن أن تكون قيمة سالبة, ويجب ان يكون نوع العمود رقم, ولذلك يعطيك هذا الخطأ, حاول تعديل السطر ليكون كالتالي

$table->string('country_id')->nullable();

أو يمكنك تحويل نوع العمود الى integer , بناء على اسم الحقل country_id فهو يجب أن يكون من نوع intger فيكون شكل الكود كالتالي

$table->integer('country_id')->nullable()->unsigned();

ثم نفذ الامر مرة أخرى

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
 Illuminate\Database\QueryException 

  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version fo
r the right syntax to use near 'unsigned null, `role_id` int not null default '2', `avatar` varchar(255) null...' at line 1 (SQL: create table `users` (`id` bigint
 unsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(255) not null, `google_id` varchar(255) null, `facebook_id` varchar(25
5) null, `country_id` varchar(255) unsigned null, `role_id` int not null default '2', `avatar` varchar(255) null, `avatar_original` varchar(255) null, `Account_Ver
ification` tinyint(1) not null default '0', `email_verified_at` timestamp null, `password` varchar(255) not null, `remember_token` varchar(100) null, `created_at`
timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at C:\xampp\htdocs\joabk\vendor\laravel\framework\src\Illuminate\Database\Connection.php:692
    688         // If an exception occurs when attempting to run a query, we'll format the error
    689         // message to include the bindings with SQL, which will make this exception a
    690         // lot more helpful to the developer instead of just the database's errors.
    691         catch (Exception $e) {
   692             throw new QueryException(
    693                 $query, $this->prepareBindings($bindings), $e
    694             );
    695         }
    696     }

  1   C:\xampp\htdocs\joabk\vendor\laravel\framework\src\Illuminate\Database\Connection.php:479
      PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your Maria
DB server version for the right syntax to use near 'unsigned null, `role_id` int not null default '2', `avatar` varchar(255) null...' at line 1")

  2   C:\xampp\htdocs\joabk\vendor\laravel\framework\src\Illuminate\Database\Connection.php:479
      PDO::prepare("create table `users` (`id` bigint unsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(255) not null, `g
oogle_id` varchar(255) null, `facebook_id` varchar(255) null, `country_id` varchar(255) unsigned null, `role_id` int not null default '2', `avatar` varchar(255) nu
ll, `avatar_original` varchar(255) null, `Account_Verification` tinyint(1) not null default '0', `email_verified_at` timestamp null, `password` varchar(255) not nu
ll, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci'")

 

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 3 دقائق مضت قال محمد أبو عواد:

المشكلة أنك تحاول اعطاء خاصية unsigned لعمود من نوع سلسلة نصية, وهذا غير منطقي, الخطأ بالتحديد في هذا السطر


$table->string('country_id')->nullable()->unsigned();

الخاصية unsigned هو قيد على قيمة العمود بأنه لا يمكن أن تكون قيمة سالبة, ويجب ان يكون نوع العمود رقم, ولذلك يعطيك هذا الخطأ, حاول تعديل السطر ليكون كالتالي


$table->string('country_id')->nullable();

أو يمكنك تحويل نوع العمود الى integer , بناء على اسم الحقل country_id فهو يجب أن يكون من نوع intger فيكون شكل الكود كالتالي


$table->integer('country_id')->nullable()->unsigned();

ثم نفذ الامر مرة أخرى

شكرا

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...