craftconomy3 icon indicating copy to clipboard operation
craftconomy3 copied to clipboard

Creating a Towny town doesnt work 'worldName' cannot be null

Open TKwSni opened this issue 5 years ago • 5 comments

Hi,

When creating a town using towny, it gives me this error.

https://pastebin.com/raw/uqYdccvs

Any way to fix it please ? i'm running my server with this plugin and this is very important, as nobody can create any towns atm.

Thank you!

TKwSni avatar Oct 19 '19 02:10 TKwSni

Hi @Blackyvk, thanks for reporting this issue.

I had a look into it and found out that Towny tries to create an account for the town. Craftconomy3 adds the name of the world to the account but it cannot determine it if the account holder is not a player. This shouldn't be a problem since the column definition for the world name also accepts null values. Do you have phpmyadmin or any other mysql administration tool to have a look a the table structure of the balance table? If so it would be helpful if you send me a screenshot of the table structure / definition.

Thanks in advance and best regards.

pavog avatar Oct 21 '19 12:10 pavog

Thank you for reply, here is my balance table, I think I tried to remove the "NOT NULL" from worldName and for that i had to remove the PRIMARY KEY, but then I got duplicates error when trying to create a town.

CREATE TABLE `aiu_balance` (
  `balance` double DEFAULT NULL,
  `worldName` varchar(255) NOT NULL DEFAULT '',
  `username_id` int(11) NOT NULL DEFAULT '0',
  `currency_id` varchar(50) NOT NULL DEFAULT '',
  PRIMARY KEY (`worldName`,`username_id`,`currency_id`),
  KEY `aiu_fk_balance_account` (`username_id`),
  KEY `aiu_fk_balance_currency` (`currency_id`),
  CONSTRAINT `aiu_fk_balance_account` FOREIGN KEY (`username_id`) REFERENCES `aiu_account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `aiu_fk_balance_currency` FOREIGN KEY (`currency_id`) REFERENCES `aiu_currency` (`name`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

TKwSni avatar Oct 21 '19 17:10 TKwSni

Ah now I get it. The initial column definition " + WORLD_NAME_FIELD + " varchar(255)," (from here) does not add a not null / not nullable condition. But when you create a primary key with this column it makes the column not nullable automagically.

From MySQL Reference:

PRIMARY KEY

A unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently). A table can have only one PRIMARY KEY. The name of a PRIMARY KEY is always PRIMARY, which thus cannot be used as the name for any other kind of index.

Unfortunately I cannot change the primary key in order to remove the world name from it.

I think the best solution would be to somehow determine the world name of the world the town is in and use it in this function.

I need to dig deeper into this and may need a few days to fix this. Thanks for you patience.

pavog avatar Oct 22 '19 16:10 pavog

@pavog Hello, I just noticed this, is there a build with this fix working? I want to test

TKwSni avatar Dec 30 '20 18:12 TKwSni

@pavog Hello, I just noticed this, is there a build with this fix working? I want to test

Hi, I released a new version today. Can you test it? See here

pavog avatar Mar 22 '21 14:03 pavog