craftconomy3
craftconomy3 copied to clipboard
Creating a Towny town doesnt work 'worldName' cannot be null
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!
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.
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;
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 Hello, I just noticed this, is there a build with this fix working? I want to test
@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