Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django : Table doesn't exist

I dropped some table related to an app. and again tried the syncdb command

python manage.py syncdb

It shows error like

django.db.utils.ProgrammingError: (1146, "Table 'someapp.feed' doesn't exist")

models.py

class feed(models.Model):
    user = models.ForeignKey(User,null=True,blank=True)
    feed_text = models.CharField(max_length=2000)
    date = models.CharField(max_length=30)
    upvote = models.IntegerField(default=0)
    downvote = models.IntegerField(default=0)

    def __str__(self):
        return feed.content

What I can do to get the tables for that app ?

like image 814
Wickkiey Avatar asked Dec 20 '14 19:12

Wickkiey


3 Answers

  1. drop tables (you already did),
  2. comment-out the model in model.py,
  3. and ..

if django version >= 1.7:

python manage.py makemigrations python manage.py migrate --fake 

else

python manage.py schemamigration someapp --auto python manage.py migrate someapp --fake 
  1. comment-in your model in models.py
  2. go to step 3. BUT this time without --fake
like image 89
doniyor Avatar answered Sep 19 '22 02:09

doniyor


For those that may still be having trouble (like me), try this out:

Comment out all the URL's in the main app's urls.py

Then go ahead and run migrations:

$ ./manage.py makemigrations
$ ./manage.py migrate

The problem was alleviated by removing the ()'s

    solved_time = models.DateTimeField('solved time', default=timezone.now())

to

    solved_time = models.DateTimeField('solved time', default=timezone.now)

I got this answer from reddit

like image 24
Keith Yong Avatar answered Sep 21 '22 02:09

Keith Yong


What solved my problem in situation when manage.py setmigration and then migrate to the SQL database is not working properly did is following:

  1. Run command : python manage.py migrate --fake MyApp zero
  2. After that: python manage.py migrate MyApp

And the problem that rises with connections.py and and after running correctly the migration command is solved! At least for me.

I'm using Python (3.x), MySQL DB, Django (3.x), and I was in situation when I needed after some time of successfully creating tables in my database, that some error regarding connections.py raises. But, above commands helped. I hope they will help all those who are having these type of problems.

like image 29
MilanovicFUL Avatar answered Sep 18 '22 02:09

MilanovicFUL