当前位置:网站首页>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
边栏推荐
- Use of polarscatter function in MATLAB
- 一文读懂数仓中的pg_stat
- Clion mingw64 Chinese garbled code
- Move base parameter analysis and experience summary
- Introduction to database system - Chapter 1 introduction [conceptual model, hierarchical model and three-level mode (external mode, mode, internal mode)]
- Server to server (S2S) event (adjust)
- 记一次 .NET 某新能源系统 线程疯涨 分析
- Battle Atlas: 12 scenarios detailing the requirements for container safety construction
- JS slow motion animation principle teaching (super detail)
- [1] Basic knowledge of ros2 - summary version of operation commands
猜你喜欢

flask session伪造之hctf admin

LED light of single chip microcomputer learning notes

"New red flag Cup" desktop application creativity competition 2022

如何让join跑得更快?

Introduce six open source protocols in detail (instructions for programmers)
![[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?](/img/fb/17e029b1d955965d7e2e0f58701d91.png)
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?

2022-7-7 Leetcode 844.比较含退格的字符串

Ogre introduction

Build a secure and trusted computing platform based on Kunpeng's native security

Cinnamon taskbar speed
随机推荐
2022-7-6 beginner redis (I) download, install and run redis under Linux
Realbasicvsr test pictures and videos
JS slow motion animation principle teaching (super detail)
1、深拷贝 2、call apply bind 3、for of for in 区别
toRaw和markRaw
Error lnk2019: unresolved external symbol
《厌女:日本的女性嫌恶》摘录
记一次 .NET 某新能源系统 线程疯涨 分析
Custom thread pool rejection policy
Ikvm of toolbox Net project new progress
clion mingw64中文乱码
云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
Evolution of customer service hotline of dewu
Oracle advanced (V) schema solution
Distributed transaction solution
Leecode3. Longest substring without repeated characters
Problems that cannot be accessed in MySQL LAN
"New red flag Cup" desktop application creativity competition 2022
作战图鉴:12大场景详述容器安全建设要求
带你掌握三层架构(建议收藏)