(Sorry for all of the database questions lately. Just doing some "Spring Cleaning" before I go live!!)
So one of the things I have been doing is checking to be sure I have Indexes and Foreign Keys on the right fields. And in a few cases, I forgot to set a FK for Lookup Tables.
One of these instances is on my "visitor_log" table, which includes...
- member_viewed_id (U1)(FK)
- visitor_id (U2)(FK)
- created_on (U3)
For this table, each FK maps back to my "member" table.
Now, I had a FK for "member_viewed_id" and all was well. But I forgot to set up a FK for "visitor_id".
The problem is that if a NON-MEMBER visits someone's profile, then I do an INSERT but just stick a "0" in for the "visitor_id".
Having numerous records with ID=0 means that creating a FK won't work, since there is no corresponding record in the "member" table.
I thought this would be easy enough, by creating a "dummy member" with ID=0, but when I do an INSERT - using phpMyAdmin - it is getting numbered as the greatest ID.
Here are the field specs...
Field Type Attributes Null Default
id mediumint(8) UNSIGNED No auto_increment
Any suggestions what to do here?
1.) Can I have a Member ID = 0 ??
2.) Is there a way to have a Foreign Key that doesn't blow up when my "visitor_log" table has an ID=0 but there is no member with an ID=0??
It would be an enormous task if I have to change all of my code to insert some non-zero number for non-members, so I am hoping some of the things I mentioned above are reasonable workarounds... :-/