尽管之前的条目正常,但无法将记录添加到数据库 [英] Cannot add record to database despite previous entries being OK

查看:123
本文介绍了尽管之前的条目正常,但无法将记录添加到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪,我在Visual Studio 2017中创建了一个SQL Server Express项目,现在正在使用SQL Server Management Studio将一些数据输入数据库表。



我已进入联赛表中的前三行,但第四(杰克逊)拒绝,尽管数据相同......请帮助!!!



我正在尝试将数据添加到联赛数据库& Foreign Key链接指向LeagueTypes Id&是名字后的第一个数据,它在所有4个条目中都是1。



LeagueTypes数据如下......



This is bizarre, I have created a SQL Server Express Project in Visual Studio 2017 and am now using SQL Server Management Studio to enter some data into the Database Tables.

I have entered the first three Rows in my Leagues Table but the 4th (Jackson) is rejecting, despite the data being identical ... please help !!!

I am trying to add data to the Leagues Database & the Foreign Key link is to the LeagueTypes Id & is the first data after the name, it's 1 in all 4 entries.

LeagueTypes Data is as follows ...

Quote:

1 SNAIL

2 EMAIL

3 ONLINE

4 PREMIER

5 VETERANS

NULL NULL

1 SNAIL
2 EMAIL
3 ONLINE
4 PREMIER
5 VETERANS
NULL NULL





联赛数据如下......





Leagues Data is as follows ...

引用:

3 CHURCHILL 1 19 0 16 4 12 2018-01-06

4 DISRAELI 1 19 0 16 4 12 2018-01-16

5 GLADSTONE 1 19 0 16 4 12 2018-01-09

NULL JACKSON 1 19 0 16 4 12 2018-01-15

NULL NULL NULL NULL NULL NULL NULL NULL NULL

3 CHURCHILL 1 19 0 16 4 12 2018-01-06
4 DISRAELI 1 19 0 16 4 12 2018-01-16
5 GLADSTONE 1 19 0 16 4 12 2018-01-09
NULL JACKSON 1 19 0 16 4 12 2018-01-15
NULL NULL NULL NULL NULL NULL NULL NULL NULL





错误消息是第4行中的数据未提交。错误源:.Net SQL客户端数据提供程序。错误消息:INSERT语句与FOREIGN KEY约束FK_Leagues_LeagueTypes冲突。冲突发生在数据库KADB,表dbo.LeagueTypes,列Id。该声明已被终止。



我尝试过:



用Google搜索错误,检查结构,检查数据



The Error Message is "The data in Row 4 was not committed. Error source: .Net SQL Client Data Provider. Error Message: The INSERT statement conflicted with the FOREIGN KEY constraint FK_Leagues_LeagueTypes. The conflict occurred in database KADB, Table dbo.LeagueTypes, Column Id. The statement has been terminated."

What I have tried:

Googled the error, checked the structure, checked the data

推荐答案

查看错误消息:

Look at the error message:
The INSERT statement conflicted with the FOREIGN KEY constraint FK_Leagues_LeagueTypes. The conflict occurred in database KADB, Table dbo.LeagueTypes, Column Id.

该表与另一个表有外键关系,你正在尝试向ID表中插入一个值,该列不存在(或者更可能不存在)该表。

检查表定义,并确保没有错误的外键或者类似:如果你不能解决问题,发布实际的SQL表定义并显示当前存在的实际数据,以及你正在使用的INSERT语句失败。

The table has a Foreign key relationship with a different table, and you are trying to insert a value to the ID column which does not (or more likely cannot) exist in that table.
Check your table definitions, and make sure you haven't got the foreign keys the wrong way round or similar: If you can't work it out, post the actual SQL table definitions and show the actual data that currently exists, plus the INSERT statement you are using that fails.


这篇关于尽管之前的条目正常,但无法将记录添加到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆