Convert customer id

That means there is a violation of the constraint currently, which could explain your issue.

The ID’s aren’t matching across tables.

thanks, do you know how I can resolve the issue?

It’s test data, so, go into that table and make the client_id’s on the project table correlate with the customer table ID’s to start with. Then add the constraint.

In your code, you will need to make sure when a project is added to the table, that it uses the correct customer id for the insert.

Hi astonecipher,

I’ve updated the projects table so the column is ‘customer_id’ and I’ve also updated the customers table so the primary key reads ‘customer_id’

I tried running the script again that you asked but it still gave me the same result and the table results still leave the ‘customer name’ column blank

Thanks

Yes, but did you actually fix the data in the tables so that the customer id stored in the projects table matches the values that are defined in the customers table?

Basically, what @phdr said. The constraint will always fail if the constraint is not valid. So, if you have a customer with id’s 1-10 and are trying to enforce a constraint that a project has to have a valid customer attached, you can’t have a project that is attached to customer id 35.

It doesn’t matter what you call the column, the data is what matters the most.

thanks guys, my code it working ok now. I had copied the data and the client_id’s were 1,2 etc but on the customer table the ids started at 6

thanks for your help

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service