Reputation: 797
I have a postgresql RDS instance on aws free tier with my ec2 instance. I should have used EB, but didn't really know about it until I had a lot built out and am not excited about starting over on a new ami. I am trying to build my first interaction with the db, have a table there called server_config, created as:
CREATE TABLE SERVER_CONFIGS
(
config_key VARCHAR(63) NOT NULL,
config_value VARCHAR(63) NOT NULL,
UNIQUE (config_key)
);
INSERT INTO SERVER_CONFIGS (config_key,config_value)
VALUES ('ClientMustVerify','TRUE');
INSERT INTO SERVER_CONFIGS (config_key,config_value)
VALUES ('Auditing','FALSE');
COMMIT;
and in my django app, I have: models.py:
from django.db import models
class serverConfig(models.Model):
config_key = models.CharField(max_length=63)
config_value = models.CharField(max_length=63)
excerpt of view.py:
from limbo.models import serverConfig
def editServer(request):
myConfigs = serverConfig.objects.all()
configHtml = ""
# for item in myConfigs #serverConfig.objects.values()
# configHtml += item.config_key + "\t" + item.config_value + "\n"
if request.method == 'POST':
form = serverForm(request.POST)
if form.is_valid():
integer = form.cleaned_data['int_field']
request.session['integer'] = integer
# call out to limboLogic.py to update values, add them to the session
message = 'The value \'' + str(integer) + '\' has been updated.'
return render(request, 'limboHtml/ServerConfiguration.html', {'form': form, 'SubmitMessage': message, 'CurrentConfigs': myConfigs})
else:
message = 'The server configuration has NOT been updated.' + '\n'
message += ', '.join("%s=%r" % (key,val) for (key,val) in form.errors.iteritems()) + '\n'
# message += ', '.join("%s=%r" % (key,val) for (key,val) in form.non_field_errors.iteritems()) + '\n'
return render(request, 'limboHtml/ServerConfiguration.html', {'form': form, 'SubmitMessage': message, 'CurrentConfigs': myConfigs})
# if a GET (or any other method) we'll create a blank form
try:
del request.session['integer']
except KeyError:
pass
form = serverForm()
return render(request, 'limboHtml/ServerConfiguration.html', {'form': form, 'SubmitMessage': '', 'CurrentConfigs': myConfigs})
error message:
File "/home/ec2-user/limbo/limboenv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) ProgrammingError: relation "limbo_serverconfig" does not exist LINE 1: ...ig_key", "limbo_serverconfig"."config_value" FROM "limbo_ser...
Why is it appending limbo_ at the start of the table? any way I can change this? should I just use my app name (or is that my project name? they're called the same thing...stupid polls tutorial) in the tables?
Django 1.10 and python 2.7 on a linux ami on ec2
Upvotes: 0
Views: 1699
Reputation: 11070
Django creates a table for each of your models. The default name of the table will be app_name + '_' + model_name
. If you do not want that to be the table's name, you can override it by specifying db_table
in the models's Meta class
Ref: https://docs.djangoproject.com/en/1.10/ref/models/options/#db-table
Suggestion
Please do not use the app with the same name as the project to write your application logic. That app should always contain only the project settings
Upvotes: 3