Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kanchan186's avatar

SQLSTATE[HY000]: General error: 1364 Field 'c_id' doesn't have a default value (SQL: insert into `states` (`s_name`, `updated_at`, `created_at`) values (nm, 2019-08-16 07:07:55, 2019-08-16 07:07:55))

0 likes
9 replies
Nakov's avatar

You are trying to create a record without providing a value for a non nullable field. Share the code where the error appears as the body of your message, not just the error in the title. Same error has appeared 100 times already, so you can search for that too.

Kanchan186's avatar
{{csrf_field()}}
                        <label>Enter state</label>
                        <input type="text" name="s_name">
                    
                        <input type="submit" name="">
                    
                </form>
Kanchan186's avatar

how to get selected option value id and insert into another table in laravel

siangboon's avatar

The issue is clear, double check the table schema on the c_id column and decide whether it should be nullable or set some default value, otherwise, ensure everything insert/update with a value..

Kanchan186's avatar

i want to insert a selected country-> c_id option value in a state table

but i dont know how to do that

please share the sample code for dyanmic dropdown box using foreign key

tykus's avatar

If you have a select element, then make sure it (i) has a name attribute (ii) each valid option has a value - being the id (or c_id?) of each country:`

<select name ="c_id">
    @foreach($countries as $country)
        <option value="{{$country->id}}">{{$country->name}}</option>
    @endforeach
</select>

Also make sure that the c_id field is fillable on the State model.

This assumes the primary key on Country is id and the foreign key on State is c_id; you should modify as necessary

Kanchan186's avatar

hello sir, can u please send the sample code for dynamic dropdown box using foreign key in laravel

Please or to participate in this conversation.