title: How to handle blank entries in MySQL
body: <p>I have been struggling with entering blank values in MySQL. For example, the code:</p>
  <pre><code>INSERT INTO `tablename` (column1, column2) VALUES ('value1', '');
  </code></pre>
  <p>will not work. I always get the following error:</p>
  <pre><code>#1265 - Data truncated for column 'column2' at row 1
  </code></pre>
  <p>However, when I run either of the two statements:</p>
  <pre><code>INSERT INTO `tablename` (column1, column2) VALUES ('value1', 'value2');
  </code></pre>
  <p>or</p>
  <pre><code>INSERT INTO `tablename` (column1, column2) VALUES ('value1', NULL);
  </code></pre>
  <p>the query works just fine. The default value for column2 has been set as &quot;0&quot;, still no luck.</p>
  <p>I'm facing this issue with all columns in all tables. My application is such that there will be blank entries (cannot be changed). This feature was working fine earlier, I started getting this error when I shifted the application code to another server.</p>
  <p>MySQL server version: 8.0.22 - MySQL Community Server - GPL</p>
  <p>Table structure is given below:</p>
  <p><a href="https://i.stack.imgur.com/khsuO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/khsuO.png" alt="enter image description here" /></a></p>
  <p>I'm facing the error in all columns. Any help would be much appreciated!</p>
  <p>Table schema:</p>
  <pre><code>CREATE TABLE `recordnew` (
   `id` int NOT NULL AUTO_INCREMENT,
   `timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `course_id` int DEFAULT NULL,
   `subject_id` int DEFAULT NULL,
   `teacher_id` int DEFAULT NULL,
   `student_id` int DEFAULT NULL,
   `month` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
   `attendance` int DEFAULT NULL,
   `totalclasses` int DEFAULT NULL,
   `tutorialattendance` int DEFAULT NULL,
   `tutorialclassestotal` int DEFAULT NULL,
   `practicalattendance` int DEFAULT NULL,
   `practicalclassestotal` int DEFAULT NULL,
   `testmarks` double(11,2) DEFAULT '0.00',
   `assignmentmarks` double(11,2) DEFAULT '0.00',
   PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=68612 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Attendance &amp; Internal Assessment Record'
  </code></pre>
  <p>My actual query:</p>
  <pre><code>INSERT INTO `recordnew` 
              (`course_id`, 
               `subject_id`, 
               `teacher_id`, 
               `student_id`, 
               `month`, 
               `attendance`, 
               `totalclasses`, 
               `testmarks`, 
               `assignmentmarks`, 
               `tutorialattendance`, 
               `tutorialclassestotal`, 
               `practicalattendance`, 
               `practicalclassestotal`) 
  VALUES      ('13', 
               '17', 
               '10', 
               '1704', 
               'Marks', 
               '0', 
               '0', 
               '15', 
               '', 
               '0', 
               '0', 
               '0', 
               '0') 
  </code></pre>
  <p>Error for the above query:</p>
  <pre><code>#1265 - Data truncated for column 'assignmentmarks' at row 1
  </code></pre>
  <p>Other SQL query:</p>
  <pre><code>INSERT INTO `recordnew` 
              (`course_id`, 
               `subject_id`, 
               `teacher_id`, 
               `student_id`, 
               `month`, 
               `attendance`, 
               `totalclasses`, 
               `testmarks`, 
               `assignmentmarks`, 
               `tutorialattendance`, 
               `tutorialclassestotal`, 
               `practicalattendance`, 
               `practicalclassestotal`) 
  VALUES      ('13', 
               '17', 
               '10', 
               '1704', 
               '', 
               '0', 
               '0', 
               '15', 
               '0', 
               '0', 
               '0', 
               '0', 
               '0') 
  </code></pre>
  <p>Error for above query:</p>
  <pre><code>#1265 - Data truncated for column 'month' at row 1
  </code></pre>