我试图用nodejs创建一个表,但是当我运行js文件时,它给了我这个错误:
C:\Users\User\Documents\apiofeverything>npm run build
> apiofeverything@1.0.0 build C:\Users\User\Documents\apiofeverything
> node build.js
[INFO] Checking if database exists...
[INFO] Existing database file has been deleted.
[INFO] Database connection succeeded.
[INFO] Creating table for postcodes...
[ERROR] Error while creating table!
[ERROR] SQLITE_RANGE: column index out of range
一些故事:
我基本上是在尝试将某种大型网络发送给您,然后将请求发送给它,并返回很多信息(不要问我为什么要这样做,有时我只是喜欢挑战) 。在撰写本文时,我仅使用spacetime添加了时区/时区功能。
我正在尝试实现某种功能,即有人可以用英国邮政编码的一部分向服务器发出请求,并且它将向他们发送有关该信息的所有信息(基本上是表的所有列)。我本可以将CSV文件导入到ram中,但是我是一个复杂的人,并且以极其复杂的方式进行操作。如果您想知道我是否从here获取英国邮政编码数据。
我以前没有将SQLite与NodeJS一起使用,因此我可能在这里犯了一个非常明显的错误。这是代码段(您可以查看完整的代码here):
var sql = 'CREATE TABLE ukpostcodes (id INTEGER NOT NULL PRIMARY KEY, postcode TEXT NOT NULL, status TEXT NOT NULL, usertype TEXT NOT NULL, easting INTEGER, northing INTEGER, positional_quality_indicator INTEGER NOT NULL, country TEXT NOT NULL, latitude NUMERIC NOT NULL, longitude NUMERIC NOT NULL, postcode_no_space TEXT NOT NULL, postcode_fixed_width_seven TEXT NOT NULL, postcode_fixed_width_eight TEXT NOT NULL, postcode_area TEXT NOT NULL, postcode_district TEXT NOT NULL, postcode_sector TEXT NOT NULL, outcode TEXT NOT NULL, incode TEXT NOT NULL);';
console.info("[INFO] Creating table for postcodes...");
db.run(sql, ['C'], function(err) {
if (err) {
console.error("[ERROR] Error while creating table!");
return console.error("[ERROR] " + err.message);
}
console.info("[INFO] Created table for postcodes.");
});
请告诉我如何解决此问题,因为我无法弄清楚! 我尝试了许多事情,包括在表名中添加引号,更改事物的顺序,使用谷歌搜索(除其他外),到目前为止没有任何效果。 如果我犯了更多的错误(可能是我犯了),那么,如果您愿意,请解决这些错误,并将pull request提交到我的存储库中!
答案 0 :(得分:0)
@Shawn确实是正确的。我已经删除了['C']
,它起作用了。
现在我唯一需要弄清楚的是为什么数据库不会插入行。
我的愚蠢问题现在在github https://github.com/TheJoeCoder/apiofeverything/issues/1
上感谢您的帮助