Truffle 无法识别合约更改,也不会部署它

问题描述

我有一个有点奇怪的情况..我能够将我的合同部署到本地 Ganache 实例:

松露迁移--网络开发

但是,现在当我对合约进行任何更改并运行相同的命令时,我的合约会被编译,但最后我得到

网络最新

现在我不确定为什么会这样?合约不一样,虽然我只改了几行代码和参数,返回值都一样,请问是这个原因吗?

另外,我认为它适用于:

松露部署 --reset

但是我明白了:

Compiling your contracts...
===========================
Everything is up to date,there is nothing to compile.

Something went wrong while attempting to connect to the network. Check your network configuration.

Could not connect to your Ethereum client with the following parameters:
    - host       > 127.0.0.1
    - port       > 7545
    - network_id > 5777

现在奇怪的是,当我使用 --reset 选项运行命令时尝试使用端口 7545...因为我的 truffle-config 指向端口 8545:

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  contracts_build_directory: path.join(__dirname,"client/src/contracts"),networks: {
    develop: {
      host: "127.0.0.1",port: 8545,network_id: "*",}
  },// Configure your compilers
  compilers: {
    solc: {
      version: "0.8.4",// Fetch exact version from solc-bin (default: truffle's version)
     }
    }
  },};

我之前确实在 7545 上运行过 Ganuche 作为实验,但它已经有一段时间没有在该端口上运行了,并且

松露迁移--网络开发

能够连接并执行初始迁移。只是现在它不会选择任何新的变化。任何想法发生了什么?

解决方法

不,松露只会迁移未执行的迁移,如文档所述: Running migrations - Command

如果您的迁移之前已成功运行,则 truffle migrate 将从上次运行的迁移开始执行,仅运行新创建的迁移。如果不存在新的迁移,则 truffle migrate 根本不会执行任何操作。您可以使用 --reset 选项从头开始运行所有迁移。

因此,如果您已经迁移了合同,则应执行:

truffle migrate --reset