Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] More a SQL thingie... but hoping someone can help - table name does not exist
#1

[eluser]boltsabre[/eluser]
Hi guys,

I'm getting this error when trying to insert some data into a new table I've just created:

Quote:A Database Error Occurred

Error Number: 1146

Table 'workandtravdatabase.travel_insurance_reviews_pending' doesn't exist

INSERT INTO `travel_insurance_reviews_pending` .....

And the model doing the inserting is:

Code:
public function insertNewPendingReview($data){
        $query = $this->db->insert('travel_insurance_reviews_pending', $this->db->escape($data));
        if ($query){
            return true;
        }else{
            return false;
        }
    }


I am really at a loss as to why I'm getting this message (mind you it's late here, that could be the problem!). I know the table exists, I just created it, and I copied it's name straight from my phpmyadmin screen into my model. I've double, triple checked it - it does exist! And it's also the correct DB name (I'm only using one DB in this application, and all my other inserts are working and inserting into tables...

Any thoughts would be greatly appreciated. Thanks in advance.
#2

[eluser]boltsabre[/eluser]
Okay, so I changed the table name from 'travel_insurance_reviews_pending' to 'travelInsuranceReviewsPending' and it's working fine... I was under the impression that you could use underscores in table names (and I actually have several others with underscores that work okay, but only one underscore, not three). But obviously something is amiss here.

If anyone knows why I'd love to know!
#3

[eluser]toopay[/eluser]
It simply because at MySQL 'sometable' is different with 'some_table'.
#4

[eluser]osci[/eluser]
The limit is 64 characters for table names and there are no restrictions to underscores as of MYSQL manual.

I did a quick check renaming one of my tables to travel_insurance_reviews_pending and tried an insert and it worked with no problems. MySQL 5.1 here.
#5

[eluser]jmadsen[/eluser]
it is strange, and most likely some sort of late-night typo.

Whenever I have an issue of this sort, I always run $this->db->last_query() and check exactly what is being created (and paste it into phpmyadmin) before doing anything else. give that a try if you still want that table named in that manner
#6

[eluser]adityamenon[/eluser]
Quote:$this->db->last_query()

Thanks! I remember searching the User Guide in panic for a function like that, and I thought CI didn't have one like it... Noting in my head!
#7

[eluser]boltsabre[/eluser]
Thanks to all the replies everyone... woke up this morning and changed it back from travelInsuranceReviewPending to travel_insurance_reviews_pending and all is good, it's working this time.

I think perhaps jmadsen was correct with his 'late night type' comment.

And thanks for this snippet, $this->db->last_query(), I've added it to my CI 'troubleshooting guide', I'll be making use of it next time I run into a problem (I'm building up a nice little list... means I have to post on here less and less, which is a good thing for all of us :-D




Theme © iAndrew 2016 - Forum software by © MyBB