如何修复 dbWriteTable 错误 "unable to find an inherited method for function 'dbWriterTable' for signature...?"

How to fix dbWriteTable error "unable to find an inherited method for function 'dbWriterTable' for signature...?"

我想从 R 中的数据框向 MySQL 中插入数据。我设法使用 dbConnect 从 R 无问题地连接到 MySQL,但是当我尝试使用 dbWriteTable 插入数据时,我不断收到错误

unable to find an inherited method for function 'dbWriterTable' for signature '"integer", "character", "data.frame"'.

现在,我已经尝试了此处提到的建议解决方案 ,但此解决方案对我不起作用。我的原始代码是

dbWriteTable(conn, "Date", france$Date)

因为我在 MySQL 中的 table 称为 Date 而我在 R 中的数据框称为 france 并且有一列 Date 包含日期(此列的类型也是日期)。在提出解决方案后,我的代码变成了

dbWriteTable(conn, "Date", data.frame(dat=france$Date), row.names=FALSE, append=TRUE)

但我遇到了同样的错误。我尝试按照以下解决方案 RMySQL dbWriteTable with field.types 中的说明添加 field.types=list("date"),但出现相同的错误。

最后,我尝试将 dbSendQuerypaste() 一起使用,按照此处的建议手动插入我的数据 How to insert integer values with query in MySQL in R? 但我再次遇到同样的错误!

这让我发疯。任何帮助将不胜感激。

您是否尝试连接到您的数据库?我遇到了同样的错误,当我检查连接时,它已断开。确保检查与 db 的连接,然后 运行 dbWriteTable 命令。它应该有效

我遇到了同样的错误,因为我提供给 dbWriteTable() 的对象不是 data.frame。

要修复它,我先将对象转换为 data.frame

dat <- as.data.frame(dat)
dbWriteTable(con, "mydbtable", dat)