简体   繁体   中英

truffle migrate only migrating first contract, not the second

the command "truffle migrate" works properly (no errors) but only migrates "Migrations.sol". It does not even attempt to migrate with 2_deploy_contracts.js

1_initial_migration.js:

var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

Migrations.sol:

enter code herepragma solidity ^0.4.25;

contract Migrations {
  address public owner;
  uint public last_completed_migration;

  modifier restricted() {
    if (msg.sender == owner) _;
  }

  function Migration() public {
    owner = msg.sender;
  }

  function setCompleted(uint completed) restricted public{
    last_completed_migration = completed;
  }

  function upgrade(address new_address) restricted public{
    Migrations upgraded = Migrations(new_address);
    upgraded.setCompleted(last_completed_migration);
  }
}

2_deploy_contracts.js:

var Election = artifacts.require("./Election.sol");

module.exports = function(deployer) {
  deployer.deploy(Election);
};

Election.sol:

pragma solidity ^0.4.25;

contract Election {
  // Store candidate
  // Read candidate
  string public candidate;

  // Constructor
  // Our constructor will be run when the contract gets deployed, so must be public
  constructor() public{
      candidate = "Candidate 1";
  }
}

Solution: I deleted my project folder and rebuilt it. This fixed it. Not sure exactly what the issue was.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM