【问题标题】:LARAVEL row cloning getting select SQL errorLARAVEL行克隆获取选择SQL错误
【发布时间】:2023-03-22 05:04:02
【问题描述】:

嗨,我已经被困在这里好几天了, 我正在尝试使用复制方法从我的数据库中克隆一行。但我得到了错误

这是我的代码:

 foreach($e_inserts as $e_data){
$enrollment = \App\Enrollment::find($e_data['enrollment_id']); //CLONE ENROLLMENTS
                                $new_enrollment = $enrollment->replicate();
                                $new_enrollment->term_id = $input['term_to'];
                                $new_enrollment->enrollment_status = 'waiving';
                                $new_enrollment->save();
}

我在插入时遇到选择错误

1SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row (SQL: insert into `enrollments` (`user_id`, `participation_id`, `term_id`, `email`, `ssn`, `student_id`, `effective_date`, `termination_date`, `last_name`, `first_name`, `middle_initial`, `dob`, `gender_code`, `identify_as`, `academic_level`, `enrollee_category`, `address`, `address2`, `city`, `state`, `zip`, `zip_reserve`, `phone`, `alt_phone`, `notification_phone`, `emergency_contact_first_name`, `emergency_contact_last_name`, `emergency_contact_relationship`, `emergency_contact_phone`, `emergency_contact_email`, `beneficiary_contact_first_name`, `beneficiary_contact_last_name`, `beneficiary_contact_relationship`, `beneficiary_contact_phone`, `beneficiary_contact_email`, `academic_status`, `opt_status`, `enrollment_status`, `dependents`, `spouse`, `agree`, `no_us_address`, `country_of_study`, `home_country`, `ead_start_date`, `ead_end_date`, `action_taken`, `completed`, `status_updated_at`, `deleted_at`, `carrier_sent`, `carrier_member_id`, `custom_history`, `locked`, `updated_at`, `created_at`) values (59536, 728, 2777, smartfox.manuel+carryover_waived_2@gmail.com, , test_waived_2, ?, ?, Email, Match, , 2000-01-01, M, , UNDG, DOM, 6162 Rotary Way, , Joshua Tree, CO, 92252, , test_waived_2, , none, test_waived_2, test_waived_2, test_waived_2, test_waived_2, , ?, ?, ?, ?, ?, FT, out, waiving, 0, 0, 1, 1, ?, ?, ?, ?, 0, 2021-07-25 11:57:35, 2021-07-27 03:20:09, ?, ?, ?, ?, 0, 2021-07-27 06:30:30, 2021-07-27 06:30:30))" 

【问题讨论】:

    标签: php mysql laravel replicate database-cloning


    【解决方案1】:

    试试这个

    $new_enrollment = $enrollment->replicate()->fill([
       'term_id' = $input['term_to'];
       'enrollment_status' = 'waiving';
    ]);
    
    $new_enrollment->save();
    

    【讨论】:

    • 甚至使用了 DB :: 门面但它不起作用,我使用块函数来填充 $e_inserts 数组
    • 你能dd($enrollment)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 2012-09-01
    相关资源
    最近更新 更多