Reputation: 597
i have a laravel 5 project and i want to use the soft delete methode, but after each delete i got this sql error message:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '7' for key 'PRIMARY' (SQL: insert into `fairkatert_task` (`id`, `user_id`, `editor_id`, `title`, `task`, `status`, `deadline_date`, `deleted_at`, `created_at`, `updated_at`, `milestone_id`) values (7, 1, 1, asdasdasdasdasd, asdasdasdasdasdasdasda, open, 2016-12-28 00:00:00, 2015-10-02 07:16:26, 0000-00-00 00:00:00, 0000-00-00 00:00:00, 0))
i tried to turn off the timestamps but it doesn't stop, i google it and i can't find any solution for me.
migration:
public function up()
{
Schema::create('task', function(Blueprint $table)
{
$table->increments('id');
$table->string('user_id')->references('id')->on('user')->onDelete('cascade');
$table->integer('editor_id')->references('id')->on('user')->onDelete('cascade');
$table->string('title');
$table->text('task');
$table->enum('status', array('open', 'close', 'reopen'))->default('open');
$table->timestamp('deadline_date');
$table->softDeletes();
$table->timestamps();
});
}
model:
<?php
namespace App\Http\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Task extends Model
{
use SoftDeletes;
public $timestamps = true;
protected $table = 'task';
protected $fillable = [ 'user_id', 'editor_id', 'title', 'task', 'status', 'deadline_date' ];
protected $dates = [ 'deadline_date', 'deleted_at', 'created_at', 'updated_at' ];
thank you for help.
Upvotes: 1
Views: 1638
Reputation: 597
Thank you two i have found my problem.
$task->delete();
$task->save();
I dont why, but i used the save method after deleting the record. That it was so easy, problem solved.
Upvotes: 1