当前位置:网站首页>mysql ”Invalid use of null value“ 解决方法
mysql ”Invalid use of null value“ 解决方法
2022-07-07 11:48:00 【全栈程序员站长】
1.问题描述
因为要更改”information”表中的”编号”列为非空,使用数据库查询语句“alter table information modify ‘编号’ varchar(255) not null”可以更改其他的列,但只是在编号列出错,错误信息为Invalid use of NULL value。
很是奇怪,其他列使用该命令可以查,为什么仅有编号列无法查。
2.错误原因
出现该错误的原因可能是因为已存在的数据的‘编号’列为null,与not null的设置冲突。(查到的原因)。
我自己认为是因为在刚开始新建数据表时,将该列的表结构已经设置,在后续进行更改的时候会因为与之前的设置有冲突(至于为什么这里更改时不能更改,我也没太理解),因为之前我在新建表的时候将编号列的结构属性设置了。
鉴于无法设置为非空,所以通过新建列并设置好not null,便可以成功。
3.解决办法
1)添加新列,设置列的结构属性。
alter table information add column ‘yyy’ varchar(255) not null first; -新添加列yyy至第一列.
2)将出错的列内容复制到新列中并删除出错列
update information set yyy=’编号’; —将’编号’列的所有值复制到yyy列.
alter table information drop ‘编号’; —删除出错的列.
3)修改新列名为出错的列名
alter table information change ‘yyy’ ‘编号’ varchar(255) not null;
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113291.html原文链接:https://javaforall.cn
边栏推荐
- cmake 学习使用笔记(一)
- postgresql array类型,每一项拼接
- JS slow motion animation principle teaching (super detail)
- [1] ROS2基础知识-操作命令总结版
- Deep understanding of array related problems in C language
- ROS机器人更换新雷达需要重新配置哪些参数
- LeetCode_二分搜索_中等_153.寻找旋转排序数组中的最小值
- LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
- 2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
- 为租客提供帮助
猜你喜欢
Navicat运行sql文件导入数据不全或导入失败
Leecode3. Longest substring without repeated characters
OSI seven layer model
Realize the IP address home display function and number home query
The delivery efficiency is increased by 52 times, and the operation efficiency is increased by 10 times. See the compilation of practical cases of financial cloud native technology (with download)
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
.net core 关于redis的pipeline以及事务
Final review notes of single chip microcomputer principle
Introduction to database system - Chapter 1 introduction [conceptual model, hierarchical model and three-level mode (external mode, mode, internal mode)]
xshell连接服务器把密钥登陆改为密码登陆
随机推荐
Leecode3. Longest substring without repeated characters
clion mingw64中文乱码
[1] Basic knowledge of ros2 - summary version of operation commands
Use of polarscatter function in MATLAB
Ways to improve the performance of raspberry pie
Oracle advanced (V) schema solution
最佳实践 | 用腾讯云AI意愿核身为电话合规保驾护航
PostgreSQL array type, each splice
Supply chain supply and demand estimation - [time series]
MySQL error 28 and solution
Excerpt from "misogyny: female disgust in Japan"
How far can it go to adopt a cow by selling the concept to the market?
1、深拷贝 2、call apply bind 3、for of for in 区别
Build a secure and trusted computing platform based on Kunpeng's native security
Learning breakout 2 - about effective learning methods
2022-7-6 Leetcode 977. Square of ordered array
高等数学---第八章多元函数微分学1
Help tenants
一文读懂数仓中的pg_stat
Getting started with MySQL