2

I have transfered my project from MySQL to PostgreSQL and tried to drop the column as result of previous issue, because after I removed the problematic column from models.py and saved. error didn't even disappear. Integer error transferring from MySQL to PostgreSQL

Tried both with and without quotes.

ALTER TABLE "UserProfile" DROP COLUMN how_many_new_notifications;

Or:

ALTER TABLE UserProfile DROP COLUMN how_many_new_notifications;

Getting the following:

ERROR:  relation "UserProfile" does not exist

Here's a model, if helps:

 class UserProfile(models.Model):
    user = models.OneToOneField(User)
    how_many_new_notifications = models.IntegerField(null=True,default=0)
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])

I supposed it might have something to do with mixed-case but I have found no solution through all similar questions.

Community
  • 1
  • 1

2 Answers2

0

Yes, Postgresql is a case aware database but django is smart enough to know that. It converts all field and it generally converts the model name to a lower case table name. However the real problem here is that your model name will be prefixed by the app name. generally django table names are like:

<appname>_<modelname>

You can find out what exactly it is by:

from myapp.models import UserProfile
print (UserProfile._meta.db_table)

Obviously this needs to be typed into the django shell, which is invoked by ./manage.py shell the result of this print statement is what you should use in your query.

e4c5
  • 52,766
  • 11
  • 101
  • 134
  • I can't exactly get, what is right now. My app is named 'blog' so I tried 'blog_UserProfile' but it 'doesn't exits' –  Dec 17 '16 at 15:25
  • 1
    why don't you just print UserProfile._meta.db_table as suggested? – e4c5 Dec 17 '16 at 15:44
  • "ERROR: cross-database references are not implemented" plus I don't really understand the syntax. First is clear, but but what is _meta here for? –  Dec 17 '16 at 16:04
  • well, what I got in shell is 'blog_userprofile' exactly what I have tried –  Dec 17 '16 at 16:40
  • the same error ' relation "blog_userprofile" does not exist' –  Dec 17 '16 at 17:49
  • please, take a look http://stackoverflow.com/questions/41202674/postgresql-models-py-is-not-transformed-into-database-scheme –  Dec 17 '16 at 21:24
  • 1
    Now it sounds like your migration hasn't run. Looking at your new question. – e4c5 Dec 18 '16 at 00:28
0
  • Client: DataGrip
  • Database engine: PostgreSQL

For me this worked opening a new console, because apparently from the IDE cache it was not recognizing the table I had created.

Steps to operate with the tables of a database:

  1. Database (Left side panel of the IDE) >
  2. Double Click on PostgreSQL - @localhost >
  3. Double Click on the name of the database >
  4. Right click on public schema >
  5. New > Console

GL

Braian Coronel
  • 22,105
  • 4
  • 57
  • 62