MySql Error: 1364 Field 'display_name' doesn't have default value
MySQL is most likely in STRICT mode.
Try running SET GLOBAL sql_mode=''
or edit your my.cnf to make sure you aren't setting STRICT_ALL_TABLES
or the like.
General error:1364 :Field 'dis' does not have a default value
You are not saving any data to dis field in your database, instead dis input field is saving data to gender field in your database. Do it like this
$student->dis=$request->dis;
or assign some default value to dis field in your database.
ERROR 1364 (HY000): Field 'Name' doesn't have a default value
Apparently, you have a column called name
which is declared NOT NULL
and has no DEFAULT
value. INSERT
inserts new rows and usually you want values for some or all of the columns.
I suspect that what you really want is not INSERT
, but UPDATE
-- to change values within a row:
UPDATE table1
SET X = SUBSTRING_INDEX(XYZ, '-', 1),
Y = SUBSTRING_INDEX(SUBSTRING_INDEX(XYZ, '-', -2), '-', 1),
Z = SUBSTRING_INDEX(SUBSTRING_INDEX(XYZ, '-', -1), '-', 2);
MySQL conditional insert causing Error Code 1364: Field doesn't have a default value
An INSERT
statement is used to add new rows to a table. It looks like what you want to do is add values to the column you just created, in the existing rows. You would do this with an UPDATE
statement instead of an INSERT
statement:
UPDATE [LOW_PRIORITY] [IGNORE] table_reference
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
The simple version, without unnecessary options, would look like this:
UPDATE table_reference SET col_name=expr WHERE where_condition;
In this case, expr
will be a constant expression – 1
– if you want to leave the column NULL
in all rows where your condition doesn't match.
General error: 1364 Field 'published' doesn't have a default value
While you save a some records in the table but some feild you're not passing so it should have default value or else null
Here I see mistake as you passed nulltable
it should be nullable
.
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->string('slug');
$table->integer('parent_id')->nullable();
$table->tinyinteger('published',0)->nullable();
$table->integer('created_by')->nullable();
$table->integer('modified_by')->nullable();
$table->timestamps();
});
General error: 1364 Field 'manufacturer_name' doesn't have a default value
See if this helps.
$file = fopen('https://opensky-network.org/datasets/metadata/aircraftDatabase.csv', 'r');
$headersArray = [];
$i = 0;
$headers = fgetcsv($file);
foreach ($headers as $key => $value) {
array_push($headersArray, $value);
}
while ($i < 50) {
$line = fgetcsv($file);
$comb = array_combine($headersArray, $line);
// Look up manuf to see if we already inserted it.
// Hopefully name isn't duplicated
$manuf = DB::table('manufacturer')->where('name', $comb['manufacturername'])->first();
// Only insert if it isn't already there
if ( ! $manuf ) {
$manufId = DB::table('manufacturer')->insertGetId(array(
'name' => $comb['manufacturername'],
));
} else {
$manufId = $manuf->id;
}
DB::table('planes')->insert(array(
'icao24' => $comb['icao24'],
'manufacturer_name' => $manufId
));
}
Migrations and foreign keys
Schema::create('planes', function (Blueprint $table) {
$table->bigIncrements('id')->autoIncrement();
$table->string('icao24');
$table->bigInteger('manufacturer_name')->unsigned()->default(1); // (1)
$table->foreign('manufacturer_name')->references('id')->on('manufacturer'); // (2)
$table->timestamps();
});
Migrations only describe how to build tables in the database. They don't cause data to be inserted into tables. By defining (1) and (2) above you
are defining a column and describing how that column relates to another table.
When inserting data into the tables, your code must insert the correct
foreign key values. The migration or the database is not going to do that for you.
Related Topics
Is There a Good PHP Geolocation Service
PHP - Get Key Name of Array Value
How to Password Protect Folder/Page Using PHP Without a Db or Username
What Is the Equivalent of JavaScript's Encodeuricomponent in PHP
How to Fetch Associative Array Grouped by the Values of a Specified Column with Pdo
Magic _Get Getter for Static Properties in PHP
How to Send a Status Code in PHP, Without Maintaining an Array of Status Names
Curl and Ping - How to Check Whether a Website Is Either Up or Down
Getting Node's Text in PHP Dom
Paypal Smart Subscribe Server Side
Sorting Multidim Array: Prioritize If Column Contains Substring, Then Order by a Second Column
Detecting Image Type from Base64 String in PHP
Does Utc Observe Daylight Saving Time
Best Way to Process Large Xml in PHP
Convert Month from Name to Number