hoadv / employee-mgmt-laravel5.4-adminlte

The project is using laravel 5.4 and adminlte
MIT License
140 stars 183 forks source link

Create employee gives the following error! #2

Closed aiimon22 closed 6 years ago

aiimon22 commented 7 years ago

(2/2) QueryException SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (callcentre.employees, CONSTRAINT employees_company_id_foreign FOREIGN KEY (company_id) REFERENCES company (id)) (SQL: insert into employees (lastname, firstname, middlename, address, city_id, state_id, country_id, zip, age, birthdate, date_hired, department_id, division_id, picture, company_id, updated_at, created_at) values (Aiman, Ahmed, Aiman, Izzudheen Magu, 20329, M. Rankoralige, 1, 1, 1, 20329, 29, 1990/03/01, 2017/07/24, 1, 1, avatars/JdzVGpL3M6G2bJFq9GY35xsyOsmYmjlf0OhilvQY.jpeg, 0, 2017-07-01 16:00:37, 2017-07-01 16:00:37))

aiimon22 commented 7 years ago

I followed the steps from the youtube video. Please help!

marcio72vieira commented 7 years ago

To solve the above problem, follow the steps: 1 - Access the "company" table in your database and enter any record. Example: id = 1; Name = Company XYZ 2 - In the Controller "store" method: "EmployeeManagementControlle.php", change the line below $ Input ['company_id'] = 0; for this $ Input ['company_id'] = 1; // where 1 is equal to "id" of the record inserted in step 1

marcio72vieira commented 7 years ago

Of course! You can solve the above question by implementing a "tinker" or "seed" to populate the table.

hoadv commented 6 years ago

Fixed it