Master Details view Foreign key

Hardus

Member
I am having trouble with the master details view. Somewhere im doing something wrong. I created a main table and linked another table in mysql to it and in dadabik I linked the linked table in master details view selecting the table and foreign key.

Mysql is not updating the foreign key with the right number, so my entries is not displaying in the master details view.

When I use phpmyadmin and change the foreign keys all to 1 then the entries appear in master details view.

expences.png


[pre]
CREATE TABLE `expences` (
`idexpences` int(11) NOT NULL AUTO_INCREMENT,
`expences_expense` varchar(45) DEFAULT NULL,
`expences_ammount` int(11) DEFAULT NULL,
`expences_total` int(11) DEFAULT NULL,
`debt_cancell_idpersonal_details` int(10) unsigned NOT NULL,
PRIMARY KEY (`idexpences`),
UNIQUE KEY `idexpences_UNIQUE` (`idexpences`),
KEY `fk_expences_debt_cancell_idx` (`debt_cancell_idpersonal_details`),
CONSTRAINT `fk_expences_debt_cancell` FOREIGN KEY (`debt_cancell_idpersonal_details`) REFERENCES `debt_cancell` (`idpersonal_details`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
[/pre]



[pre]
You are using DaDaBIK version 9.2-Monterosso enterprise, installed on 11-15-2018 (installation code: 140855bc739c14ccd4), the latest version of DaDaBIK is 9.2-Monterosso released on 11-07-2018

You are runnning the last release of DaDaBIK

PHP Version: 7.2.10-0ubuntu0.18.04.1

mysql version: 5.7.24-0ubuntu0.18.04.1

Web server: Apache/2.4.29 (Ubuntu)

Client: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36
[/pre]
 

Hardus

Member
After recreating the tables I normally get this when inserting an master details view item, then I need to change it in mysql to NULL, then I can insert the values:

[pre]
[08] Error: during query execution. INSERT INTO `expences` (`expences_expense`, `expences_ammount`, `expences_total`) VALUES ('cell', '800', '1234')
The DBMS server said: SQLSTATE[HY000]: General error: 1364 Field 'debt_cancell_idpersonal_details' doesn't have a default value
[/pre]
 

eugenio

Administrator
Staff member
Hello,
I am sorry but I don't understand the issue, can you try to explain it again?

A master/details view is just a way to show in the same page a form from a table and one or more result grids with items coming from related tables. Is the master/details view working correctly when the data you have is correct?

Best,
 

Hardus

Member
When I add data in Master details view, it don't show up, it says successfully added but then not on the list.

When I check the table, the data is there. If I manually edit the data with phpmyadmin and change the foreign key to 1 which is the main data record number, I refresh the dadabik page then the data shows.

3rd data record inserted.

image.png


On phpmyadmin:

image.png


First 2 I had to change by hand the foreign key and it worked.

Dadabik is like this by default::

image.png





I even tried to change like this with no effect:

image.png




After the linking of the master details view for the first time when I attempt to add a record it tells me this:

[pre]
[08] Error: during query execution. INSERT INTO `expences` (`expences_expense`, `expences_ammount`, `expences_total`) VALUES ('cell', '800', '1234')
The DBMS server said: SQLSTATE[HY000]: General error: 1364 Field 'debt_cancell_idpersonal_details' doesn't have a default value
[/pre]

I then need to change the value of the foreign key in mysql to "Defualt Null", then I am able to insert data but it doesnt update the primary key in the slave table with the value its supposed to.
 

eugenio

Administrator
Staff member
Hello,
I think the problem is just that you don't have the field debt_cancell_idpersonal_details in your insert form, you probably set INSERT->NO in permissions, if you don't show the field DaDaBIK doesn't have its value.

Best,
 

eugenio

Administrator
Staff member
No, you cannot hide it but it is disabled, so users cannot change it by mistake.

Best,
 

Stephan-H

Member
No, you cannot hide it but it is disabled, so users cannot change it by mistake.

Best,
That's still correct in 2024, but the + Button in the details table form is not disabled. How can I prevent users to add master table records when adding a details table record?
 

Attachments

  • Screenshot 2024-01-30 110035.jpg
    Screenshot 2024-01-30 110035.jpg
    12.5 KB · Views: 1
Top